annotate src/search.c @ 5606:7c383c5784ed

Zero-terminate when passing strings to parse_integer(), lread.c src/ChangeLog addition: 2011-12-03 Aidan Kehoe <kehoea@parhasard.net> * lread.c (read1): Zero-terminate what we're giving to parse_integer(), it needs it if it's calling bignum_set_string().
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 03 Dec 2011 15:55:14 +0000
parents 56144c8593a8
children d026b665014f
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.
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
4 Copyright (C) 2001, 2002, 2010 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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5089
diff changeset
8 XEmacs is free software: you can redistribute it and/or modify it
428
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5089
diff changeset
10 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5089
diff changeset
11 option) any later version.
428
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5089
diff changeset
19 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 /* Synched up with: FSF 19.29, except for region-cache stuff. */
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 /* Hacked on for Mule by Ben Wing, December 1994 and August 1995. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
25 /* This file has been Mule-ized. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "insdel.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "opaque.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #ifdef REGION_CACHE_NEEDS_WORK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include "region-cache.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #include "syntax.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #include <sys/types.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #include "regex.h"
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
40 #include "casetab.h"
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
41 #include "chartab.h"
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
42
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
43 #define TRANSLATE(table, pos) \
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
44 (!NILP (table) ? TRT_TABLE_OF (table, (Ichar) pos) : pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #define REGEXP_CACHE_SIZE 20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
48 #ifdef DEBUG_XEMACS
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
49
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
50 /* Used in tests/automated/case-tests.el if available. */
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
51 Fixnum debug_searches;
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
52
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
53 /* Declare as int rather than Bitflags because it's used by regex.c, which
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
54 may be used outside of XEmacs (e.g. etags.c). */
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
55 int debug_regexps;
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
56 Lisp_Object Vdebug_regexps;
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
57
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
58 Lisp_Object Qsearch_algorithm_used, Qboyer_moore, Qsimple_search;
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
59
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
60 Lisp_Object Qcompilation, Qfailure_point, Qmatching;
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
61
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
62 #endif
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
63
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 /* 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
65 of that regexp, suitable for searching. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
66 struct regexp_cache
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
67 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 struct regexp_cache *next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 Lisp_Object regexp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 struct re_pattern_buffer buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 char fastmap[0400];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 /* Nonzero means regexp was compiled to do full POSIX backtracking. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 char posix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 /* The instances of that struct. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 static struct regexp_cache searchbufs[REGEXP_CACHE_SIZE];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 /* 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
80 static struct regexp_cache *searchbuf_head;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 /* 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
84 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
85 is certainly going to be called again before region-around-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 can be called).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 Since the registers are now dynamically allocated, we need to make
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 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
90 been allocated by checking search_regs.num_regs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 The regex code keeps track of whether it has allocated the search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 buffer using bits in the re_pattern_buffer. This means that whenever
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 you compile a new pattern, it completely forgets whether it has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 allocated any registers, and will allocate new registers the next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 time you call a searching or matching function. Therefore, we need
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 to call re_set_registers after compiling a new pattern or after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 setting the match registers, so that the regex functions will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 able to free or re-allocate it properly. */
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 /* 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
102 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
103 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
104 We could be more clever by not converting them until necessary, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 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
106 the positions might be out of sync or out of range.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 static struct re_registers search_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
110 /* Every function that sets the match data _must_ clear unused search
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
111 registers on success. An unsuccessful search or match _must_ preserve
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
112 the search registers. The traditional documentation implied that
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
113 any match operation might trash the registers, but in fact failures
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
114 have always preserved the match data (in GNU Emacs as well). Some
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
115 plausible code depends on this behavior (cf. `w3-configuration-data'
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
116 in library "w3-cfg").
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
117
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
118 Ordinary string searchs use set_search_regs to set the whole-string
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
119 match. That function takes care of clearing the unused subexpression
1425
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1347
diff changeset
120 registers.
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1347
diff changeset
121 */
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1347
diff changeset
122 static void set_search_regs (struct buffer *buf, Charbpos beg, Charcount len);
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
123 static void clear_search_regs (void);
1425
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1347
diff changeset
124
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 /* The buffer in which the last search was performed, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 Qt if the last search was done in a string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 Qnil if no searching has been done yet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 static Lisp_Object last_thing_searched;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 /* error condition signalled when regexp compile_pattern fails */
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 Lisp_Object Qinvalid_regexp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 /* Regular expressions used in forward/backward-word */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 Lisp_Object Vforward_word_regexp, Vbackward_word_regexp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
507
167135c7a7ae [xemacs-hg @ 2001-05-05 10:10:36 by martinb]
martinb
parents: 502
diff changeset
137 Fixnum warn_about_possibly_incompatible_back_references;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
138
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 /* range table for use with skip_chars. Only needed for Mule. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 Lisp_Object Vskip_chars_range_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
142 static Charbpos simple_search (struct buffer *buf, Ibyte *base_pat,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
143 Bytecount len, Bytebpos pos, Bytebpos lim,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
144 EMACS_INT n, Lisp_Object trt);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
145 static Charbpos boyer_moore (struct buffer *buf, Ibyte *base_pat,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
146 Bytecount len, Bytebpos pos, Bytebpos lim,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
147 EMACS_INT n, Lisp_Object trt,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
148 Lisp_Object inverse_trt, int charset_base);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
149 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
150 Charbpos charbpos, Charbpos buflim, EMACS_INT n,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
151 int RE, Lisp_Object trt,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
152 Lisp_Object inverse_trt, int posix);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
153
2268
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1724
diff changeset
154 static DECLARE_DOESNT_RETURN (matcher_overflow (void));
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1724
diff changeset
155
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1724
diff changeset
156 static DOESNT_RETURN
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1724
diff changeset
157 matcher_overflow ()
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 507
diff changeset
159 stack_overflow ("Stack overflow in regexp matcher", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 /* Compile a regexp and signal a Lisp error if anything goes wrong.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 PATTERN is the pattern to compile.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 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
165 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
166 REGP is the structure that says where to store the "register"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 values that will result from matching this pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 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
169 subexpression bounds.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 POSIX is nonzero if we want full backtracking (POSIX style)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 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
172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2268
diff changeset
175 struct re_registers *UNUSED (regp), Lisp_Object translate,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
176 int posix, Error_Behavior errb)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
178 const char *val;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 reg_syntax_t old;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 cp->regexp = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 cp->buf.translate = translate;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 cp->posix = posix;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 old = re_set_syntax (RE_SYNTAX_EMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
186 val = (const char *)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 re_compile_pattern ((char *) XSTRING_DATA (pattern),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 XSTRING_LENGTH (pattern), &cp->buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 re_set_syntax (old);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 if (val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 {
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
192 maybe_signal_error (Qinvalid_regexp, 0, build_cistring (val),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 Qsearch, errb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 cp->regexp = Fcopy_sequence (pattern);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 /* 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
202 the cache.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 PATTERN is the pattern to compile.
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
204 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
205 REGP is the structure that says where to store the "register"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 values that will result from matching this pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 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
208 subexpression bounds.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 POSIX is nonzero if we want full backtracking (POSIX style)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 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
211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 struct re_pattern_buffer *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 compile_pattern (Lisp_Object pattern, struct re_registers *regp,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2268
diff changeset
214 Lisp_Object translate, Lisp_Object UNUSED (searchobj),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2268
diff changeset
215 struct buffer *UNUSED (searchbuf), int posix,
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2268
diff changeset
216 Error_Behavior errb)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 struct regexp_cache *cp, **cpp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 for (cpp = &searchbuf_head; ; cpp = &cp->next)
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 cp = *cpp;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
223 /* &&#### 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
224 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
225 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
226 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
227 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
228 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
229 cache entries for that buffer. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 if (!NILP (Fstring_equal (cp->regexp, pattern))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
231 && EQ (cp->buf.translate, translate)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 && cp->posix == posix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 /* 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
236 if (cp->next == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
238 if (!compile_pattern_1 (cp, pattern, regp, translate,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
239 posix, errb))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 /* When we get here, cp (aka *cpp) contains the compiled pattern,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 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
247 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
248 *cpp = cp->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 cp->next = searchbuf_head;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 searchbuf_head = cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 /* Advise the searching functions about the space we have allocated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 for register data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 if (regp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 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
256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 return &cp->buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 /* Error condition used for failing searches */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 Lisp_Object Qsearch_failed;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262
2268
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1724
diff changeset
263 static DECLARE_DOESNT_RETURN (signal_failure (Lisp_Object));
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1724
diff changeset
264
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1724
diff changeset
265 static DOESNT_RETURN
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 signal_failure (Lisp_Object arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
268 for (;;)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
269 Fsignal (Qsearch_failed, list1 (arg));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
272 /* 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
273 done after each regexp match that uses the search regs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 We could get a potential speedup by not converting the search registers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 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
277 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
278 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
279 probably not a great time-saver. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 fixup_search_regs_for_buffer (struct buffer *buf)
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 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 int num_regs = search_regs.num_regs;
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 for (i = 0; i < num_regs; i++)
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 if (search_regs.start[i] >= 0)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
290 search_regs.start[i] = bytebpos_to_charbpos (buf,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
291 search_regs.start[i]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 if (search_regs.end[i] >= 0)
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
293 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
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 /* Similar but for strings. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 fixup_search_regs_for_string (Lisp_Object string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 int num_regs = search_regs.num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 /* #### bytecount_to_charcount() is not that efficient. This function
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
305 could be faster if it did its own conversion (using INC_IBYTEPTR()
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 and such), because the register ends are likely to be somewhat ordered.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (Even if not, you could sort them.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 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
310 not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 for (i = 0; i < num_regs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 if (search_regs.start[i] > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 search_regs.start[i] =
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
316 string_index_byte_to_char (string, search_regs.start[i]);
428
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 if (search_regs.end[i] > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 search_regs.end[i] =
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
321 string_index_byte_to_char (string, search_regs.end[i]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 looking_at_1 (Lisp_Object string, struct buffer *buf, int posix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 Lisp_Object val;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
331 Bytebpos p1, p2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 Bytecount s1, s2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 REGISTER int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 struct re_pattern_buffer *bufp;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
335 struct syntax_cache scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
336 struct syntax_cache *scache = &scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
337
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 bufp = compile_pattern (string, &search_regs,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (!NILP (buf->case_fold_search)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
341 ? XCASE_TABLE_DOWNCASE (buf->case_table) : Qnil),
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
342 wrap_buffer (buf), buf, posix, ERROR_ME);
428
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 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 /* Get pointers and sizes of the two strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 that make up the visible portion of the buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
349 p1 = BYTE_BUF_BEGV (buf);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
350 p2 = BYTE_BUF_CEILING_OF (buf, p1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 s1 = p2 - p1;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
352 s2 = BYTE_BUF_ZV (buf) - p2;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
353
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
354 /* 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
355 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
356 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
357 that this can happen.)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
358
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
359 #### 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
360 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
361 reentrancy, though. Fix this. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
362
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
363 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
364 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
365 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
366 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
367 buf, scache);
428
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 if (i == -2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 matcher_overflow ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 val = (0 <= i ? Qt : Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 if (NILP (val))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
374 return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 int num_regs = search_regs.num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 for (i = 0; i < num_regs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 if (search_regs.start[i] >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
380 search_regs.start[i] += BYTE_BUF_BEGV (buf);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
381 search_regs.end[i] += BYTE_BUF_BEGV (buf);
428
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 }
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
384 last_thing_searched = wrap_buffer (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 fixup_search_regs_for_buffer (buf);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
386 return val;
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 DEFUN ("looking-at", Flooking_at, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 Return t if text after point matches regular expression REGEXP.
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
391 When the match is successful, this function modifies the match data
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
392 that `match-beginning', `match-end' and `match-data' access; save the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
393 match data with `match-data' and restore it with `store-match-data' if
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
394 you want to preserve them. If the match fails, the match data from the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
395 previous success match is preserved.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 Optional argument BUFFER defaults to the current buffer.
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 (regexp, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 return looking_at_1 (regexp, decode_buffer (buffer, 0), 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 DEFUN ("posix-looking-at", Fposix_looking_at, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 Return t if text after point matches regular expression REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 Find the longest match, in accord with Posix regular expression rules.
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
407 When the match is successful, this function modifies the match data
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
408 that `match-beginning', `match-end' and `match-data' access; save the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
409 match data with `match-data' and restore it with `store-match-data' if
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
410 you want to preserve them. If the match fails, the match data from the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
411 previous success match is preserved.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 Optional argument BUFFER defaults to the current buffer.
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 (regexp, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
417 return looking_at_1 (regexp, decode_buffer (buffer, 0), 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2268
diff changeset
422 struct buffer *buf, int UNUSED (posix))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 Bytecount val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 Charcount s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 struct re_pattern_buffer *bufp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
428 /* Some FSF junk with running_asynch_code, to preserve the match
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
429 data. Not necessary because we don't call process filters
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
430 asynchronously (i.e. from within QUIT). */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 CHECK_STRING (regexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 if (NILP (start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 s = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
439 Charcount len = string_char_length (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
441 CHECK_FIXNUM (start);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
442 s = XFIXNUM (start);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 if (s < 0 && -s <= len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 s = len + s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 else if (0 > s || s > len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 args_out_of_range (string, start);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 bufp = compile_pattern (regexp, &search_regs,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 (!NILP (buf->case_fold_search)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
452 ? XCASE_TABLE_DOWNCASE (buf->case_table) : Qnil),
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
453 string, buf, 0, ERROR_ME);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
456 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
457 struct syntax_cache scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
458 struct syntax_cache *scache = &scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
459
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
460 /* 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
461 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
462 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
463 that this can happen.)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
464
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
465 #### 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
466 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
467 reentrancy, though. Fix this. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
468
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 val = re_search (bufp, (char *) XSTRING_DATA (string),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 XSTRING_LENGTH (string), bis,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 XSTRING_LENGTH (string) - bis,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
472 &search_regs, string, buf, scache);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 if (val == -2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 matcher_overflow ();
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
476 if (val < 0) return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 last_thing_searched = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 fixup_search_regs_for_string (string);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
479 return make_fixnum (string_index_byte_to_char (string, val));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 DEFUN ("string-match", Fstring_match, 2, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 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
484 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
485 For index of first char beyond the match, do (match-end 0).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 `match-end' and `match-beginning' also give indices of substrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 matched by parenthesis constructs in the pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
489 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
490 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
491 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
492 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
493
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
494 -- 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
495 because of idioms like
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
496
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
497 (let ((case-fold-search nil))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
498 (string-match "^foo.*bar" string))
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
499
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
500 but the case, syntax, and category tables come from the standard tables,
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
501 which are accessed through functions `default-{case,syntax,category}-table'
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
502 and serve as the parents of the tables in particular buffer.
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
503
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
504 When the match is successful, this function modifies the match data
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
505 that `match-beginning', `match-end' and `match-data' access; save the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
506 match data with `match-data' and restore it with `store-match-data' if
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
507 you want to preserve them. If the match fails, the match data from the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
508 previous success match is preserved.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 (regexp, string, start, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
512 /* &&#### 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
513 makes more sense than prev */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 return string_match_1 (regexp, string, start, decode_buffer (buffer, 0), 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 DEFUN ("posix-string-match", Fposix_string_match, 2, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 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
519 Find the longest match, in accord with Posix regular expression rules.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 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
521 For index of first char beyond the match, do (match-end 0).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 `match-end' and `match-beginning' also give indices of substrings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 matched by parenthesis constructs in the pattern.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 Optional arg BUFFER controls how case folding is done (according to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 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
527 tables) and defaults to the current buffer.
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
528
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
529 When the match is successful, this function modifies the match data
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
530 that `match-beginning', `match-end' and `match-data' access; save the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
531 match data with `match-data' and restore it with `store-match-data' if
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
532 you want to preserve them. If the match fails, the match data from the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
533 previous success match is preserved.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 (regexp, string, start, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 return string_match_1 (regexp, string, start, decode_buffer (buffer, 0), 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 /* Match REGEXP against STRING, searching all of STRING,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 and return the index of the match, or negative on failure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 This does not clobber the match data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 Bytecount
1347
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1024
diff changeset
545 fast_string_match (Lisp_Object regexp, const Ibyte *nonreloc,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 Lisp_Object reloc, Bytecount offset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 Bytecount length, int case_fold_search,
578
190b164ddcac [xemacs-hg @ 2001-05-25 11:26:50 by ben]
ben
parents: 563
diff changeset
548 Error_Behavior errb, int no_quit)
428
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 Bytecount val;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
551 Ibyte *newnonreloc = (Ibyte *) nonreloc;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 struct re_pattern_buffer *bufp;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
553 struct syntax_cache scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
554 struct syntax_cache *scache = &scache_struct;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 bufp = compile_pattern (regexp, 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 (case_fold_search
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
558 ? XCASE_TABLE_DOWNCASE (Vstandard_case_table)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
559 : Qnil),
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
560 reloc, 0, 0, errb);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 if (!bufp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 return -1; /* will only do this when errb != ERROR_ME */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 if (!no_quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 no_quit_in_re_search = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 fixup_internal_substring (nonreloc, reloc, offset, &length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
570 /* 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
571 QUIT is GC-inhibited. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 if (!NILP (reloc))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
573 newnonreloc = XSTRING_DATA (reloc);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
574
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
575 /* 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
576 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
577 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
578 that this can happen.)
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
579
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
580 #### 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
581 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
582 reentrancy, though. Fix this. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
583
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 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
585 length, 0, reloc, 0, scache);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 no_quit_in_re_search = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 return val;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 Bytecount
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 fast_lisp_string_match (Lisp_Object regex, Lisp_Object string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 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
595 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 #ifdef REGION_CACHE_NEEDS_WORK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 /* The newline cache: remembering which sections of text have no newlines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 /* If the user has requested newline caching, make sure it's on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 Otherwise, make sure it's off.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 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
604 state of a buffer-local variable. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 newline_cache_on_off (struct buffer *buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 if (NILP (buf->cache_long_line_scans))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 /* It should be off. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 if (buf->newline_cache)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 free_region_cache (buf->newline_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 buf->newline_cache = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 }
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 /* It should be on. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 if (buf->newline_cache == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 buf->newline_cache = new_region_cache ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 /* Search in BUF for COUNT instances of the character TARGET between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 If COUNT is positive, search forwards; END must be >= START.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 If COUNT is negative, search backwards for the -COUNTth instance;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 END must be <= START.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 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
633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 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
635 direction indicated by COUNT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 If we find COUNT instances, set *SHORTAGE to zero, and return the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 position after the COUNTth match. Note that for reverse motion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 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
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 If we don't find COUNT instances before reaching END, set *SHORTAGE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 to the number of TARGETs left unfound, and return END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 If ALLOW_QUIT is non-zero, call QUIT periodically. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
646 static Bytebpos
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
647 byte_scan_buffer (struct buffer *buf, Ichar target, Bytebpos st, Bytebpos en,
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
648 EMACS_INT count, EMACS_INT *shortage, int allow_quit)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
650 Bytebpos lim = en > 0 ? en :
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
651 ((count > 0) ? BYTE_BUF_ZV (buf) : BYTE_BUF_BEGV (buf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 /* #### newline cache stuff in this function not yet ported */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 assert (count != 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 if (shortage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 *shortage = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 if (count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 #ifdef MULE
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
662 Internal_Format fmt = buf->text->format;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
663 /* 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
664 certainly can't be there. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
665 if (!ichar_fits_in_format (target, fmt, wrap_buffer (buf)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
667 *shortage = count;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
668 return lim;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
669 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
670 /* 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
671 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
672 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
673 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
674 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
675 else if (! (fmt == FORMAT_8_BIT_FIXED ||
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
676 (fmt == FORMAT_DEFAULT && ichar_ascii_p (target))))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
677 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
678 Raw_Ichar raw = ichar_to_raw (target, fmt, wrap_buffer (buf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 while (st < lim && count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
681 if (BYTE_BUF_FETCH_CHAR_RAW (buf, st) == raw)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 count--;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
683 INC_BYTEBPOS (buf, st);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
689 Raw_Ichar raw = ichar_to_raw (target, fmt, wrap_buffer (buf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 while (st < lim && count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 {
5539
4307b8e5998c Suppress "shadowed global" warnings for floor and ceil from <math.h>.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5402
diff changeset
692 Bytebpos ceiling;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
693 Ibyte *bufptr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694
5539
4307b8e5998c Suppress "shadowed global" warnings for floor and ceil from <math.h>.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5402
diff changeset
695 ceiling = BYTE_BUF_CEILING_OF (buf, st);
4307b8e5998c Suppress "shadowed global" warnings for floor and ceil from <math.h>.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5402
diff changeset
696 ceiling = min (lim, ceiling);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
697 bufptr = (Ibyte *) memchr (BYTE_BUF_BYTE_ADDRESS (buf, st),
5539
4307b8e5998c Suppress "shadowed global" warnings for floor and ceil from <math.h>.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5402
diff changeset
698 raw, ceiling - st);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 if (bufptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 count--;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
702 st = BYTE_BUF_PTR_BYTE_POS (buf, bufptr) + 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 else
5539
4307b8e5998c Suppress "shadowed global" warnings for floor and ceil from <math.h>.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5402
diff changeset
705 st = ceiling;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 if (shortage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 *shortage = count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 if (allow_quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 return st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 #ifdef MULE
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
718 Internal_Format fmt = buf->text->format;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
719 /* 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
720 certainly can't be there. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
721 if (!ichar_fits_in_format (target, fmt, wrap_buffer (buf)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
723 *shortage = -count;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
724 return lim;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
725 }
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
726 else if (! (fmt == FORMAT_8_BIT_FIXED ||
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
727 (fmt == FORMAT_DEFAULT && ichar_ascii_p (target))))
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
728 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
729 Raw_Ichar raw = ichar_to_raw (target, fmt, wrap_buffer (buf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 while (st > lim && count < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
732 DEC_BYTEBPOS (buf, st);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
733 if (BYTE_BUF_FETCH_CHAR_RAW (buf, st) == raw)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
740 Raw_Ichar raw = ichar_to_raw (target, fmt, wrap_buffer (buf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 while (st > lim && count < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 {
5539
4307b8e5998c Suppress "shadowed global" warnings for floor and ceil from <math.h>.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5402
diff changeset
743 Bytebpos floorpos;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
744 Ibyte *bufptr;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
745 Ibyte *floorptr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746
5539
4307b8e5998c Suppress "shadowed global" warnings for floor and ceil from <math.h>.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5402
diff changeset
747 floorpos = BYTE_BUF_FLOOR_OF (buf, st);
4307b8e5998c Suppress "shadowed global" warnings for floor and ceil from <math.h>.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5402
diff changeset
748 floorpos = max (lim, floorpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 /* No memrchr() ... */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
750 bufptr = BYTE_BUF_BYTE_ADDRESS_BEFORE (buf, st);
5539
4307b8e5998c Suppress "shadowed global" warnings for floor and ceil from <math.h>.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5402
diff changeset
751 floorptr = BYTE_BUF_BYTE_ADDRESS (buf, floorpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 while (bufptr >= floorptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 st--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 /* At this point, both ST and BUFPTR refer to the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 character. When the loop terminates, ST will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 always point to the last character we tried. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
758 if (*bufptr == (Ibyte) raw)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 break;
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 bufptr--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 if (shortage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 *shortage = -count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 if (allow_quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 if (count)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 return st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 /* We found the character we were looking for; we have to return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 the position *after* it due to the strange way that the return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 value is defined. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
779 INC_BYTEBPOS (buf, st);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 return st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
785 Charbpos
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
786 scan_buffer (struct buffer *buf, Ichar target, Charbpos start, Charbpos end,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 EMACS_INT count, EMACS_INT *shortage, int allow_quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
789 Bytebpos byte_retval;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
790 Bytebpos byte_start, byte_end;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
791
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
792 byte_start = charbpos_to_bytebpos (buf, start);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 if (end)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
794 byte_end = charbpos_to_bytebpos (buf, end);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
796 byte_end = 0;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
797 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
798 shortage, allow_quit);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
799 return bytebpos_to_charbpos (buf, byte_retval);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
802 Bytebpos
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
803 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
804 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
805 return byte_scan_buffer (buf, '\n', from, 0, count, 0, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
808 Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
809 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
810 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 return scan_buffer (buf, '\n', from, 0, count, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
814 Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
815 find_next_newline (struct buffer *buf, Charbpos from, int count)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 return scan_buffer (buf, '\n', from, 0, count, 0, 1);
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
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
820 Bytecount
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
821 byte_find_next_ichar_in_string (Lisp_Object str, Ichar target, Bytecount st,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 EMACS_INT count)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
824 Bytebpos lim = XSTRING_LENGTH (str) -1;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
825 Ibyte *s = XSTRING_DATA (str);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 assert (count >= 0);
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 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 /* Due to the Mule representation of characters in a buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 we can simply search for characters in the range 0 - 127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 directly. For other characters, we do it the "hard" way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 Note that this way works for all characters but the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 way is faster. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 if (target >= 0200)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 while (st < lim && count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
839 if (string_ichar (str, st) == target)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 count--;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
841 INC_BYTECOUNT (s, st);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 while (st < lim && count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
849 Ibyte *bufptr = (Ibyte *) memchr (itext_n_addr (s, st),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 (int) target, lim - st);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 if (bufptr)
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 count--;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
854 st = (Bytebpos) (bufptr - s) + 1;
428
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 st = lim;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 return st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 /* Like find_next_newline, but returns position before the newline,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 not after, and only search up to TO. This isn't just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 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
866 Charbpos
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
867 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
868 int count)
428
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 EMACS_INT shortage;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
871 Charbpos pos = scan_buffer (buf, '\n', from, to, count, &shortage, 1);
428
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 if (shortage == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 pos--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 return pos;
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
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
879 /* This function synched with FSF 21.1 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 skip_chars (struct buffer *buf, int forwardp, int syntaxp,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 Lisp_Object string, Lisp_Object lim)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
884 REGISTER Ibyte *p, *pend;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
885 REGISTER Ichar c;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 /* 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
887 a range table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 unsigned char fastmap[0400];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 int negate = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 REGISTER int i;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
891 Charbpos limit;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
892 struct syntax_cache *scache;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
893
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 if (NILP (lim))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 limit = forwardp ? BUF_ZV (buf) : BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
898 CHECK_FIXNUM_COERCE_MARKER (lim);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
899 limit = XFIXNUM (lim);
428
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 /* In any case, don't allow scan outside bounds of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 if (limit > BUF_ZV (buf)) limit = BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 if (limit < BUF_BEGV (buf)) limit = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 }
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 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 p = XSTRING_DATA (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 pend = p + XSTRING_LENGTH (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 memset (fastmap, 0, sizeof (fastmap));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 Fclear_range_table (Vskip_chars_range_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 if (p != pend && *p == '^')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 negate = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 /* Find the characters specified and set their elements of fastmap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 If syntaxp, each character counts as itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 Otherwise, handle backslashes and ranges specially */
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 while (p != pend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
925 c = itext_ichar (p);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
926 INC_IBYTEPTR (p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 if (syntaxp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 {
5542
dab422055bab Correct array bound for syntax_code_spec.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5539
diff changeset
929 if (c < 0200 && syntax_spec_code[c] < (unsigned char) Smax)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 fastmap[c] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 else
831
5d09ddada9ae [xemacs-hg @ 2002-05-09 07:15:20 by ben]
ben
parents: 826
diff changeset
932 invalid_argument ("Invalid syntax designator", make_char (c));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 else
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 if (c == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 if (p == pend) break;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
939 c = itext_ichar (p);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
940 INC_IBYTEPTR (p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 if (p != pend && *p == '-')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
944 Ichar cend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
946 /* Skip over the dash. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 if (p == pend) break;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
949 cend = itext_ichar (p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 while (c <= cend && c < 0400)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 fastmap[c] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 c++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 if (c <= cend)
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
956 Fput_range_table (make_fixnum (c), make_fixnum (cend), Qt,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 Vskip_chars_range_table);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
958 INC_IBYTEPTR (p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 if (c < 0400)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 fastmap[c] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 else
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
965 Fput_range_table (make_fixnum (c), make_fixnum (c), Qt,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 Vskip_chars_range_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 }
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
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
971 /* #### Not in FSF 21.1 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 if (syntaxp && fastmap['-'] != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 fastmap[' '] = 1;
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 /* If ^ was the first character, complement the fastmap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 We don't complement the range table, however; we just use negate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 in the comparisons below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 if (negate)
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 578
diff changeset
980 for (i = 0; i < (int) (sizeof (fastmap)); i++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 fastmap[i] ^= 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
984 Charbpos start_point = BUF_PT (buf);
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
985 Charbpos pos = start_point;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
986 Charbpos pos_byte = BYTE_BUF_PT (buf);
428
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 if (syntaxp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 {
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
990 scache = setup_buffer_syntax_cache (buf, pos, forwardp ? 1 : -1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 /* All syntax designators are normal chars so nothing strange
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 to worry about */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 if (forwardp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 {
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
995 if (pos < limit)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
996 while (fastmap[(unsigned char)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
997 syntax_code_spec
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
998 [(int) SYNTAX_FROM_CACHE
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
999 (scache, BYTE_BUF_FETCH_CHAR (buf, pos_byte))]])
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1000 {
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1001 pos++;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1002 INC_BYTEBPOS (buf, pos_byte);
879
f809bc97829a [xemacs-hg @ 2002-06-24 10:01:20 by michaels]
michaels
parents: 872
diff changeset
1003 if (pos >= limit)
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1004 break;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1005 UPDATE_SYNTAX_CACHE_FORWARD (scache, pos);
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1006 }
428
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 {
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1010 while (pos > limit)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1011 {
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1012 Charbpos savepos = pos_byte;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1013 pos--;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1014 DEC_BYTEBPOS (buf, pos_byte);
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1015 UPDATE_SYNTAX_CACHE_BACKWARD (scache, pos);
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1016 if (!fastmap[(unsigned char)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1017 syntax_code_spec
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1018 [(int) SYNTAX_FROM_CACHE
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1019 (scache, BYTE_BUF_FETCH_CHAR (buf, pos_byte))]])
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1020 {
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1021 pos++;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1022 pos_byte = savepos;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1023 break;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1024 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
1025 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 if (forwardp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 {
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1032 while (pos < limit)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 {
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1034 Ichar ch = BYTE_BUF_FETCH_CHAR (buf, pos_byte);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 if ((ch < 0400) ? fastmap[ch] :
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
1036 (NILP (Fget_range_table (make_fixnum (ch),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 Vskip_chars_range_table,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 Qnil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 == negate))
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1040 {
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1041 pos++;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1042 INC_BYTEBPOS (buf, pos_byte);
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1043 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 {
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1050 while (pos > limit)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 {
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1052 Charbpos prev_pos_byte = pos_byte;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1053 Ichar ch;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1054
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1055 DEC_BYTEBPOS (buf, prev_pos_byte);
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1056 ch = BYTE_BUF_FETCH_CHAR (buf, prev_pos_byte);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 if ((ch < 0400) ? fastmap[ch] :
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
1058 (NILP (Fget_range_table (make_fixnum (ch),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 Vskip_chars_range_table,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 Qnil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 == negate))
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1062 {
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1063 pos--;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1064 pos_byte = prev_pos_byte;
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1065 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 QUIT;
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 867
diff changeset
1072 BOTH_BUF_SET_PT (buf, pos, pos_byte);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
1073 return make_fixnum (BUF_PT (buf) - start_point);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 DEFUN ("skip-chars-forward", Fskip_chars_forward, 1, 3, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1078 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
1079 STRING is like the inside of a `[...]' in a regular expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 except that `]' is never special and `\\' quotes `^', `-' or `\\'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 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
1082 With arg "^a-zA-Z", skips nonletters stopping before first letter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 Returns the distance traveled, either zero or positive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 Optional argument BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1087 (string, limit, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1089 return skip_chars (decode_buffer (buffer, 0), 1, 0, string, limit);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 DEFUN ("skip-chars-backward", Fskip_chars_backward, 1, 3, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1093 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
1094 See `skip-chars-forward' for details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 Returns the distance traveled, either zero or negative.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 Optional argument BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1099 (string, limit, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1101 return skip_chars (decode_buffer (buffer, 0), 0, 0, string, limit);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 DEFUN ("skip-syntax-forward", Fskip_syntax_forward, 1, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 Move point forward across chars in specified syntax classes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 SYNTAX is a string of syntax code characters.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1108 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
1109 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 This function returns the distance traveled, either zero or positive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 Optional argument BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1114 (syntax, limit, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1116 return skip_chars (decode_buffer (buffer, 0), 1, 1, syntax, limit);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 DEFUN ("skip-syntax-backward", Fskip_syntax_backward, 1, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 Move point backward across chars in specified syntax classes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 SYNTAX is a string of syntax code characters.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1122 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
1123 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 This function returns the distance traveled, either zero or negative.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 Optional argument BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1128 (syntax, limit, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1130 return skip_chars (decode_buffer (buffer, 0), 0, 1, syntax, limit);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 /* Subroutines of Lisp buffer search functions. */
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 Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1137 search_command (Lisp_Object string, Lisp_Object limit, Lisp_Object noerror,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 Lisp_Object count, Lisp_Object buffer, int direction,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 int RE, int posix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1141 REGISTER Charbpos np;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1142 Charbpos lim;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 EMACS_INT n = direction;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 struct buffer *buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 if (!NILP (count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
1148 CHECK_FIXNUM (count);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
1149 n *= XFIXNUM (count);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 }
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 buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 CHECK_STRING (string);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1154 if (NILP (limit))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 lim = n > 0 ? BUF_ZV (buf) : BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
1158 CHECK_FIXNUM_COERCE_MARKER (limit);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
1159 lim = XFIXNUM (limit);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 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
1161 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
1162 Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 if (lim > BUF_ZV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 lim = BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 if (lim < BUF_BEGV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 lim = BUF_BEGV (buf);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 np = search_buffer (buf, string, BUF_PT (buf), lim, n, RE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 (!NILP (buf->case_fold_search)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1171 ? XCASE_TABLE_CANON (buf->case_table)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1172 : Qnil),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 (!NILP (buf->case_fold_search)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1174 ? XCASE_TABLE_EQV (buf->case_table)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1175 : Qnil), posix);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 if (np <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1179 if (NILP (noerror))
2268
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1724
diff changeset
1180 {
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1724
diff changeset
1181 signal_failure (string);
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1724
diff changeset
1182 RETURN_NOT_REACHED (Qnil);
61855263cb07 [xemacs-hg @ 2004-09-14 14:32:29 by james]
james
parents: 1724
diff changeset
1183 }
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1184 if (!EQ (noerror, Qt))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 if (lim < BUF_BEGV (buf) || lim > BUF_ZV (buf))
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2421
diff changeset
1187 ABORT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 BUF_SET_PT (buf, lim);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 #if 0 /* This would be clean, but maybe programs depend on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 a value of nil here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 np = lim;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 if (np < BUF_BEGV (buf) || np > BUF_ZV (buf))
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2421
diff changeset
1200 ABORT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 BUF_SET_PT (buf, np);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
1204 return make_fixnum (np);
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 trivial_regexp_p (Lisp_Object regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 Bytecount len = XSTRING_LENGTH (regexp);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1211 Ibyte *s = XSTRING_DATA (regexp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 while (--len >= 0)
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 switch (*s++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 {
1724
4af49f9a7a5c [xemacs-hg @ 2003-09-29 09:20:39 by stephent]
stephent
parents: 1468
diff changeset
1216 /* #### howcum ']' doesn't appear here, but ... */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 case '.': case '*': case '+': case '?': case '[': case '^': case '$':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 case '\\':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 if (--len < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 switch (*s++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 {
1724
4af49f9a7a5c [xemacs-hg @ 2003-09-29 09:20:39 by stephent]
stephent
parents: 1468
diff changeset
1224 /* ... ')' does appear here? ('<' and '>' can appear singly.) */
4af49f9a7a5c [xemacs-hg @ 2003-09-29 09:20:39 by stephent]
stephent
parents: 1468
diff changeset
1225 /* #### are there other constructs to check? */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 case '|': case '(': case ')': case '`': case '\'': case 'b':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 case 'B': case '<': case '>': case 'w': case 'W': case 's':
1724
4af49f9a7a5c [xemacs-hg @ 2003-09-29 09:20:39 by stephent]
stephent
parents: 1468
diff changeset
1228 case 'S': case '=': case '{': case '}':
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 /* 97/2/25 jhod Added for category matches */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 case 'c': case 'C':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 case '1': case '2': case '3': case '4': case '5':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 case '6': case '7': case '8': case '9':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 /* 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
1243 starting at position CHARBPOS and stopping at position BUFLIM,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 treating PAT as a literal string if RE is false or as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 a regular expression if RE is true.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 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
1248 than CHARBPOS.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 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
1250 than CHARBPOS.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 Returns -x if only N-x occurrences found (x > 0),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 or else the position at the beginning of the Nth occurrence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 (if searching backward) or the end (if searching forward).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 POSIX is nonzero if we want full backtracking (POSIX style)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 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
1258 static Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1259 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
1260 Charbpos buflim, EMACS_INT n, int RE, Lisp_Object trt,
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1261 Lisp_Object inverse_trt, int posix)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 Bytecount len = XSTRING_LENGTH (string);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1264 Ibyte *base_pat = XSTRING_DATA (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 REGISTER EMACS_INT i, j;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1266 Bytebpos p1, p2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 Bytecount s1, s2;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1268 Bytebpos pos, lim;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
1270 /* Some FSF junk with running_asynch_code, to preserve the match
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
1271 data. Not necessary because we don't call process filters
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
1272 asynchronously (i.e. from within QUIT). */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273
1425
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1347
diff changeset
1274 /* Searching 0 times means noop---don't move, don't touch registers. */
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1347
diff changeset
1275 if (n == 0)
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1347
diff changeset
1276 return charbpos;
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1347
diff changeset
1277
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 /* Null string is found at starting position. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 if (len == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1281 set_search_regs (buf, charbpos, 0);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1282 return charbpos;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1285 pos = charbpos_to_bytebpos (buf, charbpos);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1286 lim = charbpos_to_bytebpos (buf, buflim);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 if (RE && !trivial_regexp_p (string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 struct re_pattern_buffer *bufp;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1290
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1291 bufp = compile_pattern (string, &search_regs, trt,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1292 wrap_buffer (buf), buf, posix, ERROR_ME);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 /* Get pointers and sizes of the two strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 that make up the visible portion of the buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1297 p1 = BYTE_BUF_BEGV (buf);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1298 p2 = BYTE_BUF_CEILING_OF (buf, p1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 s1 = p2 - p1;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1300 s2 = BYTE_BUF_ZV (buf) - p2;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1301
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1302 while (n != 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 Bytecount val;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1305 struct syntax_cache scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1306 struct syntax_cache *scache = &scache_struct;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1307
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 QUIT;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1309 /* 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
1310 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
1311 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
1312 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
1313
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1314 #### 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
1315 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
1316 reentrancy, though. Fix this. */
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1317
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 val = re_search_2 (bufp,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1319 (char *) BYTE_BUF_BYTE_ADDRESS (buf, p1), s1,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1320 (char *) BYTE_BUF_BYTE_ADDRESS (buf, p2), s2,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1321 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
1322 n > 0 ? lim - BYTE_BUF_BEGV (buf) :
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1323 pos - BYTE_BUF_BEGV (buf), wrap_buffer (buf),
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1324 buf, scache);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 if (val == -2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 matcher_overflow ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 if (val >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 int num_regs = search_regs.num_regs;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1333 j = BYTE_BUF_BEGV (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 for (i = 0; i < num_regs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 if (search_regs.start[i] >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 search_regs.start[i] += j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 search_regs.end[i] += j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 }
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
1340 last_thing_searched = wrap_buffer (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 /* Set pos to the new position. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1342 pos = n > 0 ? search_regs.end[0] : search_regs.start[0];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 fixup_search_regs_for_buffer (buf);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1344 /* And charbpos too. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1345 charbpos = n > 0 ? search_regs.end[0] : search_regs.start[0];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1348 return (n > 0 ? 0 - n : n);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1349 if (n > 0) n--; else n++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 }
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1351 return charbpos;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 else /* non-RE case */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1355 int charset_base = -1;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1356 int boyer_moore_ok = 1;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2333
diff changeset
1357 Ibyte *patbuf = alloca_ibytes (len * MAX_ICHAR_LEN);
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1358 Ibyte *pat = patbuf;
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1359
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1360 #ifdef MULE
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1361 int entirely_one_byte_p = buf->text->entirely_one_byte_p;
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1362 int nothing_greater_than_0xff =
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1363 buf->text->num_8_bit_fixed_chars == BUF_Z(buf) - BUF_BEG (buf);
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1364
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1365 while (len > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1366 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1367 Ibyte tmp_str[MAX_ICHAR_LEN];
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1368 Ichar c, translated, inverse;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1369 Bytecount orig_bytelen, new_bytelen, inv_bytelen;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1370
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1371 /* 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
1372 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
1373 backslash just quotes the next character. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1374 if (RE && *base_pat == '\\')
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1375 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1376 len--;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1377 base_pat++;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1378 }
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1379 c = itext_ichar (base_pat);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1380 translated = TRANSLATE (trt, c);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1381 inverse = TRANSLATE (inverse_trt, c);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1382
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1383 orig_bytelen = itext_ichar_len (base_pat);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1384 inv_bytelen = set_itext_ichar (tmp_str, inverse);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1385 new_bytelen = set_itext_ichar (tmp_str, translated);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1386
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1387 if (boyer_moore_ok
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1388 /* Only do the Boyer-Moore check for characters needing
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1389 translation. */
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1390 && (translated != c || inverse != c))
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1391 {
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1392 Ichar starting_c = c;
4421
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1393 int charset_base_code, checked = 0;
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1394
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1395 do
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1396 {
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1397 c = TRANSLATE (inverse_trt, c);
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1398
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1399 /* If a character cannot occur in the buffer, ignore
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1400 it. */
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1401 if (c > 0x7F && entirely_one_byte_p)
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1402 continue;
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1403
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1404 if (c > 0xFF && nothing_greater_than_0xff)
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1405 continue;
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1406
4421
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1407 checked = 1;
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1408
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1409 if (-1 == charset_base) /* No charset yet specified. */
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1410 {
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1411 /* Keep track of which charset and character set row
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1412 contains the characters that need translation.
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1413
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1414 Zero out the bits corresponding to the last
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1415 byte. */
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1416 charset_base = c & ~ICHAR_FIELD3_MASK;
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1417 }
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1418 else
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1419 {
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1420 charset_base_code = c & ~ICHAR_FIELD3_MASK;
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1421
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1422 if (charset_base_code != charset_base)
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1423 {
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1424 /* If two different rows, or two different
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1425 charsets, appear, needing non-ASCII
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1426 translation, then we cannot use boyer_moore
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1427 search. See the comment at the head of
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1428 boyer_moore(). */
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1429 boyer_moore_ok = 0;
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1430 break;
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1431 }
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1432 }
4901
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1433
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1434 if (ichar_len (c) > 2)
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1435 {
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1436 /* Case-equivalence plus repeated octets throws off
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1437 the construction of the stride table; avoid this.
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1438
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1439 It should be possible to correct boyer_moore to
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1440 behave correctly even in this case--it doesn't have
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1441 problems with repeated octets when case conversion
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1442 is not involved--but this is not a critical
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1443 issue. */
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1444 Ibyte encoded[MAX_ICHAR_LEN];
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4962
diff changeset
1445 Bytecount clen = set_itext_ichar (encoded, c);
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4962
diff changeset
1446 int a, b;
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4962
diff changeset
1447 for (a = 0; a < clen && boyer_moore_ok; ++a)
4901
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1448 {
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4962
diff changeset
1449 for (b = a + 1; b < clen && boyer_moore_ok; ++b)
4901
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1450 {
5016
2ade80e8c640 enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents: 4962
diff changeset
1451 if (encoded[a] == encoded[b])
4901
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1452 {
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1453 boyer_moore_ok = 0;
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1454 }
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1455 }
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1456 }
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1457
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1458 if (0 == boyer_moore_ok)
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1459 {
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1460 break;
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1461 }
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1462 }
7504864a986c Don't use Boyer-Moore if repeated octets & case-insensitive search.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4897
diff changeset
1463
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1464 } while (c != starting_c);
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1465
4421
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1466 if (!checked)
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1467 {
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1468 #ifdef DEBUG_XEMACS
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
1469 if (debug_searches)
4421
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1470 {
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1471 Lisp_Symbol *sym = XSYMBOL (Qsearch_algorithm_used);
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1472 sym->value = Qnil;
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1473 }
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1474 #endif
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1475 /* The "continue" clauses were used above, for every
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1476 translation of the character. As such, this character
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1477 is not to be found in the buffer and neither is the
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1478 string as a whole. Return immediately; also avoid
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1479 triggering the assertion a few lines down. */
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1480 return n > 0 ? -n : n;
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1481 }
69b803c646cd Fail searches immediately if searching for non-representable characters.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4414
diff changeset
1482
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1483 if (boyer_moore_ok && charset_base != -1 &&
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1484 charset_base != (translated & ~ICHAR_FIELD3_MASK))
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1485 {
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1486 /* In the rare event that the CANON entry for this
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1487 character is not in the desired set, choose one
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1488 that is, from the equivalence set. It doesn't much
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1489 matter which. */
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1490 Ichar starting_ch = translated;
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1491 do
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1492 {
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1493 translated = TRANSLATE (inverse_trt, translated);
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1494
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1495 if (charset_base == (translated & ~ICHAR_FIELD3_MASK))
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1496 break;
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1497
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1498 } while (starting_ch != translated);
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1499
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1500 assert (starting_ch != translated);
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1501
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1502 new_bytelen = set_itext_ichar (tmp_str, translated);
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1503 }
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1504 }
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1505
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1506 memcpy (pat, tmp_str, new_bytelen);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1507 pat += new_bytelen;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1508 base_pat += orig_bytelen;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1509 len -= orig_bytelen;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1510 }
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1511
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1512 if (-1 == charset_base)
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1513 {
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1514 charset_base = 'a' & ~ICHAR_FIELD3_MASK; /* Default to ASCII. */
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1515 }
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1516
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1517 #else /* not MULE */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1518 while (--len >= 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1519 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1520 /* 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
1521 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
1522 backslash just quotes the next character. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1523 if (RE && *base_pat == '\\')
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1524 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1525 len--;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1526 base_pat++;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1527 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1528 *pat++ = TRANSLATE (trt, *base_pat++);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1529 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1530 #endif /* MULE */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1531 len = pat - patbuf;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1532 pat = base_pat = patbuf;
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1533
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1534 #ifdef DEBUG_XEMACS
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
1535 if (debug_searches)
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1536 {
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1537 Lisp_Symbol *sym = XSYMBOL (Qsearch_algorithm_used);
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1538 sym->value = boyer_moore_ok ? Qboyer_moore : Qsimple_search;
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1539 }
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1540 #endif
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1541
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1542 if (boyer_moore_ok)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1543 return boyer_moore (buf, base_pat, len, pos, lim, n,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1544 trt, inverse_trt, charset_base);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1545 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1546 return simple_search (buf, base_pat, len, pos, lim, n, trt);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1547 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1548 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1549
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1550 /* 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
1551 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
1552 translation table.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1553
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1554 Return the character position where the match is found.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1555 Otherwise, if M matches remained to be found, return -M.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1556
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1557 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
1558 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
1559 boyer_moore cannot work. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1560
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1561 static Charbpos
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1562 simple_search (struct buffer *buf, Ibyte *base_pat, Bytecount len,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1563 Bytebpos pos, Bytebpos lim, EMACS_INT n, Lisp_Object trt)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1564 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1565 int forward = n > 0;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1566 Bytecount buf_len = 0; /* Shut up compiler. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1567
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1568 if (lim > pos)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1569 while (n > 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1571 while (1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1573 Bytecount this_len = len;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1574 Bytebpos this_pos = pos;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1575 Ibyte *p = base_pat;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1576 if (pos >= lim)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1577 goto stop;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1578
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1579 while (this_len > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1580 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1581 Ichar pat_ch, buf_ch;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1582 Bytecount pat_len;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1583
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1584 pat_ch = itext_ichar (p);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1585 buf_ch = BYTE_BUF_FETCH_CHAR (buf, this_pos);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1586
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1587 buf_ch = TRANSLATE (trt, buf_ch);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1588
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1589 if (buf_ch != pat_ch)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1590 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1591
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1592 pat_len = itext_ichar_len (p);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1593 p += pat_len;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1594 this_len -= pat_len;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1595 INC_BYTEBPOS (buf, this_pos);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1596 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1597 if (this_len == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1599 buf_len = this_pos - pos;
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1600 pos = this_pos;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1601 break;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 }
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1603 INC_BYTEBPOS (buf, pos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1605 n--;
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 else
4322
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1608 {
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1609 /* If lim < len, then there are too few buffer positions to hold the
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1610 pattern between the beginning of the buffer and lim. Adjust to
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1611 ensure pattern fits. If we don't do this, we can assert in the
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1612 DEC_BYTEBPOS below. */
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1613 if (lim < len)
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1614 lim = len;
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1615 while (n < 0)
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1616 {
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1617 while (1)
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1618 {
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1619 Bytecount this_len = len;
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1620 Bytebpos this_pos = pos;
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1621 Ibyte *p;
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1622 if (pos <= lim)
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1623 goto stop;
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1624 p = base_pat + len;
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1625
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1626 while (this_len > 0)
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1627 {
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1628 Ichar pat_ch, buf_ch;
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1629
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1630 DEC_IBYTEPTR (p);
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1631 DEC_BYTEBPOS (buf, this_pos);
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1632 pat_ch = itext_ichar (p);
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1633 buf_ch = BYTE_BUF_FETCH_CHAR (buf, this_pos);
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1634
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1635 buf_ch = TRANSLATE (trt, buf_ch);
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1636
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1637 if (buf_ch != pat_ch)
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1638 break;
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1639
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1640 this_len -= itext_ichar_len (p);
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1641 }
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1642 if (this_len == 0)
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1643 {
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1644 buf_len = pos - this_pos;
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1645 pos = this_pos;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1646 break;
4322
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1647 }
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1648 DEC_BYTEBPOS (buf, pos);
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1649 }
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1650 n++;
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1651 }
f70e56bb52a7 src/search.c (simple_search): Fix underrun in reverse search.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4199
diff changeset
1652 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1653 stop:
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1654 if (n == 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1655 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1656 Charbpos beg, end, retval;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1657 if (forward)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1658 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1659 beg = bytebpos_to_charbpos (buf, pos - buf_len);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1660 retval = end = bytebpos_to_charbpos (buf, pos);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1661 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1662 else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1664 retval = beg = bytebpos_to_charbpos (buf, pos);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1665 end = bytebpos_to_charbpos (buf, pos + buf_len);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1667 set_search_regs (buf, beg, end - beg);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1668
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1669 return retval;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1670 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1671 else if (n > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1672 return -n;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1673 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1674 return n;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1675 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1676
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1677 /* Do Boyer-Moore search N times for the string PAT,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1678 whose length is LEN/LEN_BYTE,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1679 from buffer position POS/POS_BYTE until LIM/LIM_BYTE.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1680 DIRECTION says which direction we search in.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1681 TRT and INVERSE_TRT are translation tables.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1682
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1683 This kind of search works if all the characters in PAT that have
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1684 (non-ASCII) translation are the same aside from the last byte. This
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1685 makes it possible to translate just the last byte of a character, and do
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1686 so after just a simple test of the context.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1687
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1688 If that criterion is not satisfied, do not call this function. You will
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1689 get an assertion failure. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1690
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1691 static Charbpos
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1692 boyer_moore (struct buffer *buf, Ibyte *base_pat, Bytecount len,
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1693 Bytebpos pos, Bytebpos lim, EMACS_INT n, Lisp_Object trt,
2333
ba4677f54a05 [xemacs-hg @ 2004-10-14 17:26:18 by james]
james
parents: 2286
diff changeset
1694 Lisp_Object inverse_trt, int USED_IF_MULE (charset_base))
446
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 /* #### Someone really really really needs to comment the workings
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1697 of this junk somewhat better.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1698
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1699 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
1700 string-searching algorithms. It's the best string-searching
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1701 algorithm out there, provided that:
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1702
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1703 a) You're not fazed by algorithm complexity. (Rabin-Karp, which
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1704 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
1705 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
1706 searching through.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1707
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1708 As the comment below tries to explain (but garbles in typical
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1709 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
1710 string match at every successive position in the text. For
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1711 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
1712 compare the last character in the string (`g') with the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1713 corresponding character in the text. If it mismatches, and
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1714 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
1715 length of the pattern because `z' does not occur anywhere
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1716 in the pattern. If the mismatching character does occur
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1717 in the pattern, we can usually still skip forward by more
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1718 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
1719 by the length of the substring "ong string" -- i.e. the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1720 largest end section of the pattern that does not contain
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1721 the mismatched character. So what we do is compute, for
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1722 each possible character, the distance we can skip forward
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1723 (the "stride") and use it in the string matching. This
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1724 is what the BM_tab holds. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1725 REGISTER EMACS_INT *BM_tab;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1726 EMACS_INT *BM_tab_base;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1727 REGISTER Bytecount dirlen;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1728 EMACS_INT infinity;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1729 Bytebpos limit;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1730 Bytecount stride_for_teases = 0;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1731 REGISTER EMACS_INT i, j;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1732 Ibyte *pat, *pat_end;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1733 REGISTER Ibyte *cursor, *p_limit, *ptr2;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1734 Ibyte simple_translate[0400];
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1735 REGISTER int direction = ((n > 0) ? 1 : -1);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1736 #ifdef MULE
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1737 Ibyte translate_prev_byte = 0;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1738 Ibyte translate_anteprev_byte = 0;
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1739 /* These need to be rethought in the event that the internal format
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1740 changes, or in the event that num_8_bit_fixed_chars disappears
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1741 (entirely_one_byte_p can be trivially worked out by checking is the
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1742 byte count equal to the char count.) */
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1743 int buffer_entirely_one_byte_p = buf->text->entirely_one_byte_p;
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1744 int buffer_nothing_greater_than_0xff =
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1745 buf->text->num_8_bit_fixed_chars == BUF_Z(buf) - BUF_BEG (buf);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1746 #endif
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1747 #ifdef C_ALLOCA
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1748 EMACS_INT BM_tab_space[0400];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1749 BM_tab = &BM_tab_space[0];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1750 #else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1751 BM_tab = alloca_array (EMACS_INT, 256);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1752 #endif
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1753
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1754 /* 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
1755 know the first (closest to the present position, in whatever
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1756 direction we're searching) character that could possibly be
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1757 the last (furthest from present position) character of a
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1758 valid match. We advance the state of our knowledge by
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1759 looking at that character and seeing whether it indeed
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1760 matches the last character of the pattern. If it does, we
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1761 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
1762 putative last characters) as far as is logically possible.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1763 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
1764 length of the pattern if the actual character appears nowhere
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1765 in the pattern, otherwise it will be the distance from the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1766 last occurrence of that character to the end of the pattern.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1767 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
1768 for characters that match the last character. This allows
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1769 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
1770 end of the permissible match region, to test for both
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1771 possible matches (when the stride goes past the end
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1772 immediately) and failure to match (where you get nudged past
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1773 the end one stride at a time).
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1774
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1775 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
1776 search is determined only by the last character of the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1777 putative match. If that character does not match, we will
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1778 stride the proper distance to propose a match that
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1779 superimposes it on the last instance of a character that
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1780 matches it (per trt), or misses it entirely if there is
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1781 none. */
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 dirlen = len * direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1784 infinity = dirlen - (lim + pos + len + len) * direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1785 /* Record position after the end of the pattern. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1786 pat_end = base_pat + len;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1787 if (direction < 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1788 base_pat = pat_end - 1;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1789 BM_tab_base = BM_tab;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1790 BM_tab += 0400;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1791 j = dirlen; /* to get it in a register */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1792 /* A character that does not appear in the pattern induces a
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1793 stride equal to the pattern length. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1794 while (BM_tab_base != BM_tab)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1795 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1796 *--BM_tab = j;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1797 *--BM_tab = j;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1798 *--BM_tab = j;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1799 *--BM_tab = j;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1800 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1801 /* We use this for translation, instead of TRT itself. We
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1802 fill this in to handle the characters that actually occur
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1803 in the pattern. Others don't matter anyway! */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1804 xzero (simple_translate);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1805 for (i = 0; i < 0400; i++)
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1806 simple_translate[i] = (Ibyte) i;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1807 i = 0;
1425
74cb069b8417 [xemacs-hg @ 2003-04-23 15:42:44 by stephent]
stephent
parents: 1347
diff changeset
1808
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1809 while (i != infinity)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1810 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1811 Ibyte *ptr = base_pat + i;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1812 i += direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1813 if (i == dirlen)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1814 i = infinity;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1815 if (!NILP (trt))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1817 #ifdef MULE
4897
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1818 Ichar ch = -1, untranslated;
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1819 Ibyte byte;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1820 int this_translated = 1;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1821
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1822 /* Is *PTR the last byte of a character? */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1823 if (pat_end - ptr == 1 || ibyte_first_byte_p (ptr[1]))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1825 Ibyte *charstart = ptr;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1826 while (!ibyte_first_byte_p (*charstart))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1827 charstart--;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1828 untranslated = itext_ichar (charstart);
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1829
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1830 ch = TRANSLATE (trt, untranslated);
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1831 if (!ibyte_first_byte_p (*ptr))
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1832 {
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1833 translate_prev_byte = ptr[-1];
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1834 if (!ibyte_first_byte_p (translate_prev_byte))
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1835 translate_anteprev_byte = ptr[-2];
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1836 }
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1837
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1838 if (ch != untranslated && /* Was translation done? */
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1839 charset_base != (ch & ~ICHAR_FIELD3_MASK))
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1840 {
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1841 /* In the very rare event that the CANON entry for this
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1842 character is not in the desired set, choose one that
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1843 is, from the equivalence set. It doesn't much matter
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1844 which, since we're building our own cheesy equivalence
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1845 table instead of using that belonging to the case
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1846 table directly.
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1847
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1848 We can get here if search_buffer has worked out that
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1849 the buffer is entirely single width. */
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1850 Ichar starting_ch = ch;
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1851 int count = 0;
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1852 do
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1853 {
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1854 ch = TRANSLATE (inverse_trt, ch);
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1855 if (charset_base == (ch & ~ICHAR_FIELD3_MASK))
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1856 break;
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1857 ++count;
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1858 } while (starting_ch != ch);
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1859
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1860 /* If starting_ch is equal to ch (and count is not one,
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1861 which means no translation is necessary), the case
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1862 table is corrupt. (Any mapping in the canon table
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1863 should be reflected in the equivalence table, and we
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1864 know from the canon table that untranslated maps to
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1865 starting_ch and that untranslated has the correct value
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1866 for charset_base.) */
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
1867 assert (1 == count || starting_ch != ch);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1868 }
4897
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1869 {
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1870 Ibyte tmp[MAX_ICHAR_LEN];
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1871 Bytecount chlen;
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1872
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1873 chlen = set_itext_ichar (tmp, ch);
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1874 byte = tmp[chlen - 1];
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1875 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 {
4897
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1879 byte = *ptr;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1880 this_translated = 0;
4897
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1881 ch = -1;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1882 }
4897
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1883
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1884 /* BYTE = last byte of character CH when represented as text */
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1885 j = byte;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1886
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1887 if (i == infinity)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1888 stride_for_teases = BM_tab[j];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1889 BM_tab[j] = dirlen - i;
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1890 /* A translation table is accompanied by its inverse -- see
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1891 comment in casetab.c. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1892 if (this_translated)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1893 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1894 Ichar starting_ch = ch;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1895 EMACS_INT starting_j = j;
4897
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1896
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1897 text_checking_assert (valid_ichar_p (ch));
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1898 do
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1899 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1900 ch = TRANSLATE (inverse_trt, ch);
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1901
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1902 if (ch > 0x7F && buffer_entirely_one_byte_p)
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1903 continue;
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1904
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1905 if (ch > 0xFF && buffer_nothing_greater_than_0xff)
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1906 continue;
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1907
4897
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1908
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1909 /* Retrieve last byte of character CH when represented as
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1910 text */
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1911 {
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1912 Ibyte tmp[MAX_ICHAR_LEN];
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1913 Bytecount chlen;
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1914
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1915 chlen = set_itext_ichar (tmp, ch);
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1916 j = tmp[chlen - 1];
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1917 }
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1918
4407
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1919 /* For all the characters that map into CH, set up
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1920 simple_translate to map the last byte into
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1921 STARTING_J. */
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1922 simple_translate[j] = (Ibyte) starting_j;
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1923 BM_tab[j] = dirlen - i;
4ee73bbe4f8e Always use boyer_moore in ASCII or Latin-1 buffers with ASCII search strings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4322
diff changeset
1924
4897
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1925 }
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1926 while (ch != starting_ch);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1927 }
4897
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1928 #else /* not MULE */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1929 EMACS_INT k;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1930 j = *ptr;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1931 k = (j = TRANSLATE (trt, j));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1932 if (i == infinity)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1933 stride_for_teases = BM_tab[j];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1934 BM_tab[j] = dirlen - i;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1935 /* 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
1936 see comment in casetab.c. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1937 while ((j = TRANSLATE (inverse_trt, j)) != k)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1938 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1939 simple_translate[j] = (Ibyte) k;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 BM_tab[j] = dirlen - i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 }
4897
91a023144e72 fix longstanding search bug involving searching for Control-1 chars
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
1942 #endif /* (not) MULE */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1943 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1944 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1945 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1946 j = *ptr;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1947
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1948 if (i == infinity)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1949 stride_for_teases = BM_tab[j];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1950 BM_tab[j] = dirlen - i;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1952 /* 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
1953 match on the far character but are subsequently
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1954 disappointed, by recording what the stride would have been
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1955 for that character if the last character had been
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1956 different. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1957 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1958 infinity = dirlen - infinity;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1959 pos += dirlen - ((direction > 0) ? direction : 0);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1960 /* loop invariant - pos points at where last char (first char if
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1961 reverse) of pattern would align in a possible match. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1962 while (n != 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1963 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
1964 Bytebpos tail_end;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
1965 Ibyte *tail_end_ptr;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1966 /* It's been reported that some (broken) compiler thinks
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1967 that Boolean expressions in an arithmetic context are
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1968 unsigned. Using an explicit ?1:0 prevents this. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1969 if ((lim - pos - ((direction > 0) ? 1 : 0)) * direction < 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1970 return n * (0 - direction);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1971 /* First we do the part we can by pointers (maybe
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1972 nothing) */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1973 QUIT;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1974 pat = base_pat;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1975 limit = pos - dirlen + direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1976 /* XEmacs change: definitions of CEILING_OF and FLOOR_OF
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1977 have changed. See buffer.h. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1978 limit = ((direction > 0)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1979 ? BYTE_BUF_CEILING_OF (buf, limit) - 1
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1980 : BYTE_BUF_FLOOR_OF (buf, limit + 1));
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1981 /* LIMIT is now the last (not beyond-last!) value POS can
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1982 take on without hitting edge of buffer or the gap. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1983 limit = ((direction > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1984 ? min (lim - 1, min (limit, pos + 20000))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1985 : max (lim, max (limit, pos - 20000)));
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1986 tail_end = BYTE_BUF_CEILING_OF (buf, pos);
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1987 tail_end_ptr = BYTE_BUF_BYTE_ADDRESS (buf, tail_end);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1988
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1989 if ((limit - pos) * direction > 20)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
1991 /* 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
1992 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
1993 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
1994 ptr2 = (cursor = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos));
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1995 /* In this loop, pos + cursor - ptr2 is the surrogate
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1996 for pos */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1997 while (1) /* use one cursor setting as long as i can */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1998 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1999 if (direction > 0) /* worth duplicating */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2000 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2001 /* Use signed comparison if appropriate to make
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2002 cursor+infinity sure to be > p_limit.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2003 Assuming that the buffer lies in a range of
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2004 addresses that are all "positive" (as ints)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2005 or all "negative", either kind of comparison
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2006 will work as long as we don't step by
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2007 infinity. So pick the kind that works when
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2008 we do step by infinity. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2009 if ((EMACS_INT) (p_limit + infinity) >
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2010 (EMACS_INT) p_limit)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2011 while ((EMACS_INT) cursor <=
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2012 (EMACS_INT) p_limit)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2013 cursor += BM_tab[*cursor];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2014 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2015 while ((EMACS_UINT) cursor <=
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2016 (EMACS_UINT) p_limit)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2017 cursor += BM_tab[*cursor];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2018 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2019 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2020 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2021 if ((EMACS_INT) (p_limit + infinity) <
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2022 (EMACS_INT) p_limit)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2023 while ((EMACS_INT) cursor >=
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2024 (EMACS_INT) p_limit)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2025 cursor += BM_tab[*cursor];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2026 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2027 while ((EMACS_UINT) cursor >=
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2028 (EMACS_UINT) p_limit)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2029 cursor += BM_tab[*cursor];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2030 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2031 /* If you are here, cursor is beyond the end of the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2032 searched region. This can happen if you match on
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2033 the far character of the pattern, because the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2034 "stride" of that character is infinity, a number
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2035 able to throw you well beyond the end of the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2036 search. It can also happen if you fail to match
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2037 within the permitted region and would otherwise
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2038 try a character beyond that region */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2039 if ((cursor - p_limit) * direction <= len)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2040 break; /* a small overrun is genuine */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2041 cursor -= infinity; /* large overrun = hit */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2042 i = dirlen - direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2043 if (!NILP (trt))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2044 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2045 while ((i -= direction) + direction != 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2046 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2047 #ifdef MULE
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2048 Ichar ch;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2049 cursor -= direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2050 /* Translate only the last byte of a character. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2051 if ((cursor == tail_end_ptr
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2052 || ibyte_first_byte_p (cursor[1]))
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2053 && (ibyte_first_byte_p (cursor[0])
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2054 || (translate_prev_byte == cursor[-1]
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2055 && (ibyte_first_byte_p (translate_prev_byte)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2056 || translate_anteprev_byte == cursor[-2]))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2057 ch = simple_translate[*cursor];
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2058 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2059 ch = *cursor;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2060 if (pat[i] != ch)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2061 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2062 #else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2063 if (pat[i] != TRANSLATE (trt, *(cursor -= direction)))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2064 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2065 #endif
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2066 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2067 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2068 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2069 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2070 while ((i -= direction) + direction != 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2071 if (pat[i] != *(cursor -= direction))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2072 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2073 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2074 cursor += dirlen - i - direction; /* fix cursor */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2075 if (i + direction == 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2076 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2077 cursor -= direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2078
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2079 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2080 Bytebpos bytstart = (pos + cursor - ptr2 +
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2081 ((direction > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2082 ? 1 - len : 0));
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2083 Charbpos bufstart = bytebpos_to_charbpos (buf, bytstart);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2084 Charbpos bufend = bytebpos_to_charbpos (buf, bytstart + len);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2085
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2086 set_search_regs (buf, bufstart, bufend - bufstart);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2087 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2088
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2089 if ((n -= direction) != 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2090 cursor += dirlen; /* to resume search */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2091 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2092 return ((direction > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2093 ? search_regs.end[0] : search_regs.start[0]);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2094 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2095 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2096 cursor += stride_for_teases; /* <sigh> we lose - */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2097 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2098 pos += cursor - ptr2;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2099 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2100 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2101 /* 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
2102 way because it covers a discontinuity */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2103 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 /* XEmacs change: definitions of CEILING_OF and FLOOR_OF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2105 have changed. See buffer.h. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 limit = ((direction > 0)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2107 ? 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
2108 : BYTE_BUF_FLOOR_OF (buf, pos - dirlen));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109 limit = ((direction > 0)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2110 ? min (limit + len, lim - 1)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2111 : max (limit - len, lim));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2112 /* LIMIT is now the last value POS can have
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2113 and still be valid for a possible match. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2114 while (1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2116 /* This loop can be coded for space rather than
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2117 speed because it will usually run only once.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2118 (the reach is at most len + 21, and typically
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2119 does not exceed len) */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2120 while ((limit - pos) * direction >= 0)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2121 /* *not* BYTE_BUF_FETCH_CHAR. We are working here
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2122 with bytes, not characters. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2123 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
2124 /* now run the same tests to distinguish going off
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2125 the end, a match or a phony match. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2126 if ((pos - limit) * direction <= len)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2127 break; /* ran off the end */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2128 /* Found what might be a match.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2129 Set POS back to last (first if reverse) char pos. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2130 pos -= infinity;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2131 i = dirlen - direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2132 while ((i -= direction) + direction != 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2133 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2134 #ifdef MULE
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2135 Ichar ch;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2136 Ibyte *ptr;
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2137 #endif
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2138 pos -= direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2139 #ifdef MULE
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2140 ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2141 if ((ptr == tail_end_ptr
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2142 || ibyte_first_byte_p (ptr[1]))
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2143 && (ibyte_first_byte_p (ptr[0])
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2144 || (translate_prev_byte == ptr[-1]
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2145 && (ibyte_first_byte_p (translate_prev_byte)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2146 || translate_anteprev_byte == ptr[-2]))))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2147 ch = simple_translate[*ptr];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 else
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2149 ch = *ptr;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2150 if (pat[i] != ch)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2151 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2152
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2153 #else
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2154 if (pat[i] !=
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2155 TRANSLATE (trt,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2156 *BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos)))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2157 break;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2158 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2160 /* Above loop has moved POS part or all the way back
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2161 to the first char pos (last char pos if reverse).
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2162 Set it once again at the last (first if reverse)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2163 char. */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2164 pos += dirlen - i- direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2165 if (i + direction == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2167 pos -= direction;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2168
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2169 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2170 Bytebpos bytstart = (pos +
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2171 ((direction > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2172 ? 1 - len : 0));
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2173 Charbpos bufstart = bytebpos_to_charbpos (buf, bytstart);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2174 Charbpos bufend = bytebpos_to_charbpos (buf, bytstart + len);
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2175
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2176 set_search_regs (buf, bufstart, bufend - bufstart);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2177 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2178
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2179 if ((n -= direction) != 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2180 pos += dirlen; /* to resume search */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 else
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2182 return ((direction > 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2183 ? search_regs.end[0] : search_regs.start[0]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2185 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2186 pos += stride_for_teases;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2187 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2189 /* We have done one clump. Can we continue? */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2190 if ((lim - pos) * direction < 0)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2191 return (0 - n) * direction;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 }
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2193 return bytebpos_to_charbpos (buf, pos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195
1024
ccaf90c5a53a [xemacs-hg @ 2002-10-02 09:29:37 by stephent]
stephent
parents: 879
diff changeset
2196 /* Record the whole-match data (beginning BEG and end BEG + LEN) and the
ccaf90c5a53a [xemacs-hg @ 2002-10-02 09:29:37 by stephent]
stephent
parents: 879
diff changeset
2197 buffer for a match just found. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199 static void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2200 set_search_regs (struct buffer *buf, Charbpos beg, Charcount len)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 /* Make sure we have registers in which to store
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203 the match position. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 if (search_regs.num_regs == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 search_regs.start = xnew (regoff_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 search_regs.end = xnew (regoff_t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 search_regs.num_regs = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2211 clear_search_regs ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 search_regs.start[0] = beg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213 search_regs.end[0] = beg + len;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
2214 last_thing_searched = wrap_buffer (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2217 /* Clear search registers so match data will be null. */
1024
ccaf90c5a53a [xemacs-hg @ 2002-10-02 09:29:37 by stephent]
stephent
parents: 879
diff changeset
2218
ccaf90c5a53a [xemacs-hg @ 2002-10-02 09:29:37 by stephent]
stephent
parents: 879
diff changeset
2219 static void
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2220 clear_search_regs (void)
1024
ccaf90c5a53a [xemacs-hg @ 2002-10-02 09:29:37 by stephent]
stephent
parents: 879
diff changeset
2221 {
ccaf90c5a53a [xemacs-hg @ 2002-10-02 09:29:37 by stephent]
stephent
parents: 879
diff changeset
2222 /* This function has been Mule-ized. */
ccaf90c5a53a [xemacs-hg @ 2002-10-02 09:29:37 by stephent]
stephent
parents: 879
diff changeset
2223 int i;
ccaf90c5a53a [xemacs-hg @ 2002-10-02 09:29:37 by stephent]
stephent
parents: 879
diff changeset
2224
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2225 for (i = 0; i < search_regs.num_regs; i++)
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2226 search_regs.start[i] = search_regs.end[i] = -1;
1024
ccaf90c5a53a [xemacs-hg @ 2002-10-02 09:29:37 by stephent]
stephent
parents: 879
diff changeset
2227 }
ccaf90c5a53a [xemacs-hg @ 2002-10-02 09:29:37 by stephent]
stephent
parents: 879
diff changeset
2228
428
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 /* Given a string of words separated by word delimiters,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2231 compute a regexp that matches those exact words
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2232 separated by arbitrary punctuation. */
428
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 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 wordify (Lisp_Object buffer, Lisp_Object string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 Charcount i, len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 EMACS_INT punct_count = 0, word_count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239 struct buffer *buf = decode_buffer (buffer, 0);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2240 Lisp_Object syntax_table = buf->mirror_syntax_table;
428
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 CHECK_STRING (string);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2243 len = string_char_length (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 for (i = 0; i < len; i++)
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2246 if (!WORD_SYNTAX_P (syntax_table, string_ichar (string, i)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 punct_count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 if (i > 0 && WORD_SYNTAX_P (syntax_table,
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2250 string_ichar (string, i - 1)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 word_count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252 }
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2253 if (WORD_SYNTAX_P (syntax_table, string_ichar (string, len - 1)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 word_count++;
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
2255 if (!word_count) return build_ascstring ("");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 /* 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
2259 need. In non-Mule, it is exact. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2260 Ibyte *storage =
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2333
diff changeset
2261 alloca_ibytes (XSTRING_LENGTH (string) - punct_count +
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262 5 * (word_count - 1) + 4);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2263 Ibyte *o = storage;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265 *o++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 *o++ = 'b';
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 for (i = 0; i < len; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2270 Ichar ch = string_ichar (string, i);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272 if (WORD_SYNTAX_P (syntax_table, ch))
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2273 o += set_itext_ichar (o, ch);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 else if (i > 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275 && WORD_SYNTAX_P (syntax_table,
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2276 string_ichar (string, i - 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277 && --word_count)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 *o++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 *o++ = 'W';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 *o++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 *o++ = 'W';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 *o++ = '*';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 *o++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288 *o++ = 'b';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 return make_string (storage, o - storage);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 DEFUN ("search-backward", Fsearch_backward, 1, 5, "sSearch backward: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 Search backward from point for STRING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 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
2297
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2298 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2299 position. The match found must not extend before that position.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2300 The value nil is equivalent to (point-min).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2301
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2302 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2303 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
2304 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2305
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2306 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2307 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2308
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 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
2310 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2311
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2312 When the match is successful, this function modifies the match data
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2313 that `match-beginning', `match-end' and `match-data' access; save the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2314 match data with `match-data' and restore it with `store-match-data' if
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2315 you want to preserve them. If the match fails, the match data from the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2316 previous success match is preserved.
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2317
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2318 See also the function `replace-match'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2320 (string, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2322 return search_command (string, limit, noerror, count, buffer, -1, 0, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 DEFUN ("search-forward", Fsearch_forward, 1, 5, "sSearch: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 Search forward from point for STRING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 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
2328
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2329 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2330 position. The match found must not extend after that position. The
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2331 value nil is equivalent to (point-max).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2332
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2333 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2334 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
2335 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2336
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2337 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2338 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2339
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340 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
2341 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2342
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2343 When the match is successful, this function modifies the match data
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2344 that `match-beginning', `match-end' and `match-data' access; save the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2345 match data with `match-data' and restore it with `store-match-data' if
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2346 you want to preserve them. If the match fails, the match data from the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2347 previous success match is preserved.
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2348
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2349 See also the function `replace-match'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2351 (string, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2353 return search_command (string, limit, noerror, count, buffer, 1, 0, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356 DEFUN ("word-search-backward", Fword_search_backward, 1, 5,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357 "sWord search backward: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 Search backward from point for STRING, ignoring differences in punctuation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359 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
2360
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2361 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2362 position. The match found must not extend before that position.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2363 The value nil is equivalent to (point-min).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2364
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2365 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2366 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
2367 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2368
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2369 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2370 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2371
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 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
2373 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2374
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2375 When the match is successful, this function modifies the match data
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2376 that `match-beginning', `match-end' and `match-data' access; save the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2377 match data with `match-data' and restore it with `store-match-data' if
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2378 you want to preserve them. If the match fails, the match data from the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2379 previous success match is preserved.
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2380
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2381 See also the function `replace-match'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2383 (string, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2385 return search_command (wordify (buffer, string), limit, noerror, count,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 buffer, -1, 1, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389 DEFUN ("word-search-forward", Fword_search_forward, 1, 5, "sWord search: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 Search forward from point for STRING, ignoring differences in punctuation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 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
2392
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2393 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2394 position. The match found must not extend after that position. The
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2395 value nil is equivalent to (point-max).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2396
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2397 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2398 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
2399 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2400
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2401 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2402 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2403
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 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
2405 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2406
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2407 When the match is successful, this function modifies the match data
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2408 that `match-beginning', `match-end' and `match-data' access; save the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2409 match data with `match-data' and restore it with `store-match-data' if
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2410 you want to preserve them. If the match fails, the match data from the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2411 previous success match is preserved.
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2412
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2413 See also the function `replace-match'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2415 (string, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2417 return search_command (wordify (buffer, string), limit, noerror, count,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 buffer, 1, 1, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 DEFUN ("re-search-backward", Fre_search_backward, 1, 5,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 "sRE search backward: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 Search backward from point for match for regular expression REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2424 Set point to the beginning of the match, and return point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2425 The match found is the one starting last in the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426 and yet ending before the origin of the search.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2427
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2428 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2429 position. The match found must not extend before that position.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2430 The value nil is equivalent to (point-min).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2431
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2432 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2433 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
2434 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2435
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2436 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2437 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2438
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 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
2440 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2441
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2442 When the match is successful, this function modifies the match data
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2443 that `match-beginning', `match-end' and `match-data' access; save the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2444 match data with `match-data' and restore it with `store-match-data' if
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2445 you want to preserve them. If the match fails, the match data from the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2446 previous success match is preserved.
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2447
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2448 See also the function `replace-match'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2450 (regexp, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2452 return search_command (regexp, limit, noerror, count, buffer, -1, 1, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 DEFUN ("re-search-forward", Fre_search_forward, 1, 5, "sRE search: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 Search forward from point for regular expression REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 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
2458
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2459 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2460 position. The match found must not extend after that position. The
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2461 value nil is equivalent to (point-max).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2462
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2463 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2464 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
2465 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2466
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2467 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2468 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2469
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 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
2471 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2472
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2473 When the match is successful, this function modifies the match data
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2474 that `match-beginning', `match-end' and `match-data' access; save the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2475 match data with `match-data' and restore it with `store-match-data' if
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2476 you want to preserve them. If the match fails, the match data from the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2477 previous success match is preserved.
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2478
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2479 See also the function `replace-match'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2481 (regexp, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2482 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2483 return search_command (regexp, limit, noerror, count, buffer, 1, 1, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 DEFUN ("posix-search-backward", Fposix_search_backward, 1, 5,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 "sPosix search backward: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 Search backward from point for match for regular expression REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 Find the longest match in accord with Posix regular expression rules.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 Set point to the beginning of the match, and return point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 The match found is the one starting last in the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 and yet ending before the origin of the search.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2493
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2494 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2495 position. The match found must not extend before that position.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2496 The value nil is equivalent to (point-min).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2497
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2498 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2499 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
2500 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2501
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2502 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2503 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2504
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 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
2506 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2507
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2508 When the match is successful, this function modifies the match data
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2509 that `match-beginning', `match-end' and `match-data' access; save the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2510 match data with `match-data' and restore it with `store-match-data' if
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2511 you want to preserve them. If the match fails, the match data from the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2512 previous success match is preserved.
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2513
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2514 See also the function `replace-match'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2516 (regexp, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2518 return search_command (regexp, limit, noerror, count, buffer, -1, 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 DEFUN ("posix-search-forward", Fposix_search_forward, 1, 5, "sPosix search: ", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 Search forward from point for regular expression REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 Find the longest match in accord with Posix regular expression rules.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524 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
2525
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2526 Optional second argument LIMIT bounds the search; it is a buffer
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2527 position. The match found must not extend after that position. The
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2528 value nil is equivalent to (point-max).
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2529
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2530 Optional third argument NOERROR, if t, means just return nil (no
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2531 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
2532 and return nil.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2533
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2534 Optional fourth argument COUNT is a repeat count--search for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2535 successive occurrences.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2536
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537 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
2538 defaults to the current buffer.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2539
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2540 When the match is successful, this function modifies the match data
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2541 that `match-beginning', `match-end' and `match-data' access; save the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2542 match data with `match-data' and restore it with `store-match-data' if
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2543 you want to preserve them. If the match fails, the match data from the
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2544 previous success match is preserved.
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2545
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2546 See also the function `replace-match'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2548 (regexp, limit, noerror, count, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2550 return search_command (regexp, limit, noerror, count, buffer, 1, 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 free_created_dynarrs (Lisp_Object cons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557 Dynarr_free (get_opaque_ptr (XCAR (cons)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 Dynarr_free (get_opaque_ptr (XCDR (cons)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 free_opaque_ptr (XCAR (cons));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 free_opaque_ptr (XCDR (cons));
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
2561 free_cons (cons);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 DEFUN ("replace-match", Freplace_match, 1, 5, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2566 Replace text matched by last search with REPLACEMENT.
4199
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2567 Leaves point at end of replacement text.
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2568 Optional boolean FIXEDCASE inhibits matching case of REPLACEMENT to source.
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2569 Optional boolean LITERAL inhibits interpretation of escape sequences.
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2570 Optional STRING provides the source text to replace.
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2571 Optional STRBUFFER may be a buffer, providing match context, or an integer
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2572 specifying the subexpression to replace.
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2573
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2574 If FIXEDCASE is non-nil, do not alter case of replacement text.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575 Otherwise maybe capitalize the whole text, or maybe just word initials,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 based on the replaced text.
4199
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2577 If the replaced text has only capital letters and has at least one
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2578 multiletter word, convert REPLACEMENT to all caps.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 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
2580 then capitalize each word in REPLACEMENT.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581
4199
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2582 If LITERAL is non-nil, insert REPLACEMENT literally.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 Otherwise treat `\\' as special:
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2584 `\\&' in REPLACEMENT means substitute original matched text.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585 `\\N' means substitute what matched the Nth `\\(...\\)'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 If Nth parens didn't match, substitute nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 `\\\\' means insert one `\\'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 `\\u' means upcase the next character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 `\\l' means downcase the next character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 `\\U' means begin upcasing all following characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 `\\L' means begin downcasing all following characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 `\\E' means terminate the effect of any `\\U' or `\\L'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 Case changes made with `\\u', `\\l', `\\U', and `\\L' override
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594 all other case changes that may be made in the replaced text.
4199
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2595
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2596 If non-nil, STRING is the source string, and a new string with the specified
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2597 replacements is created and returned. Otherwise the current buffer is the
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2598 source text.
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2599
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2600 If non-nil, STRBUFFER may be an integer, interpreted as the index of the
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2601 subexpression to replace in the source text, or a buffer to provide the
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2602 syntax table and case table. If nil, then the \"subexpression\" is 0, i.e.,
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2603 the whole match, and the current buffer provides the syntax and case tables.
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2604 If STRING is nil, STRBUFFER must be nil or an integer.
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2605
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2606 Specifying a subexpression is only useful after a regular expression match,
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2607 since a fixed string search has no non-trivial subexpressions.
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2608
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2609 It is not possible to specify both a buffer and a subexpression. If that is
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2610 desired, the idiom `(with-current-buffer BUFFER (replace-match ... INTEGER))'
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2611 may be appropriate.
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2612
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2613 If STRING is nil but the last thing matched (or searched) was a string, or
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2614 STRING is a string but the last thing matched was a buffer, an
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2615 `invalid-argument' error will be signaled. (XEmacs does not check that the
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2616 last thing searched is the source string, but it is not useful to use a
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2617 different string as source.)
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2618
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2619 If no match (including searches) has been successful or the requested
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2620 subexpression was not matched, an `args-out-of-range' error will be
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2621 signaled. (If no match has ever been conducted in this instance of
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2622 XEmacs, an `invalid-operation' error will be signaled. This is very
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
2623 rare.)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2624 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2625 (replacement, fixedcase, literal, string, strbuffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2628 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
2629 Charbpos pos, last;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 int some_multiletter_word;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631 int some_lowercase;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 int some_uppercase;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 int some_nonuppercase_initial;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2634 Ichar c, prevc;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635 Charcount inslen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636 struct buffer *buf;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2637 Lisp_Object syntax_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 int mc_count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 Lisp_Object buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 int_dynarr *ul_action_dynarr = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 int_dynarr *ul_pos_dynarr = 0;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
2642 int sub = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 int speccount;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2645 CHECK_STRING (replacement);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646
4199
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2647 /* Because GNU decided to be incompatible here, we support the following
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2648 baroque and bogus API for the STRING and STRBUFFER arguments:
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2649 types interpretations
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2650 STRING STRBUFFER STRING STRBUFFER
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2651 nil nil none 0 = index of subexpression to replace
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2652 nil integer none index of subexpression to replace
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2653 nil other ***** error *****
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2654 string nil source current buffer provides syntax table
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2655 subexpression = 0 (whole match)
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2656 string buffer source buffer providing syntax table
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2657 subexpression = 0 (whole match)
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2658 string integer source current buffer provides syntax table
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2659 subexpression = STRBUFFER
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2660 string other ***** error *****
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2661 */
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2662
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2663 /* Do STRBUFFER first; if STRING is nil, we'll overwrite BUF and BUFFER. */
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2664
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2665 /* If the match data were abstracted into a special "match data" type
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2666 instead of the typical half-assed "let the implementation be visible"
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2667 form it's in, we could extend it to include the last string matched
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2668 and the buffer used for that matching. But of course we can't change
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2669 it as it is.
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2670 */
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2671 if (NILP (strbuffer) || BUFFERP (strbuffer))
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2672 {
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2673 buf = decode_buffer (strbuffer, 0);
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2674 }
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2675 else if (!NILP (strbuffer))
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2676 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2677 CHECK_FIXNUM (strbuffer);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2678 sub = XFIXNUM (strbuffer);
4199
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2679 if (sub < 0 || sub >= (int) search_regs.num_regs)
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2680 invalid_argument ("match data register invalid", strbuffer);
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2681 if (search_regs.start[sub] < 0)
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2682 invalid_argument ("match data register not set", strbuffer);
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2683 buf = current_buffer;
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2684 }
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2685 else
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2686 invalid_argument ("STRBUFFER must be nil, a buffer, or an integer",
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2687 strbuffer);
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2688 buffer = wrap_buffer (buf);
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2689
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 if (! NILP (string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693 if (!EQ (last_thing_searched, Qt))
4199
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2694 invalid_argument ("last thing matched was not a string", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2695 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 if (!BUFFERP (last_thing_searched))
4199
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2699 invalid_argument ("last thing matched was not a buffer", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700 buffer = last_thing_searched;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 buf = XBUFFER (buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2704 syntax_table = buf->mirror_syntax_table;
428
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 case_action = nochange; /* We tried an initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 /* but some C compilers blew it */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709 if (search_regs.num_regs == 0)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2710 signal_error (Qinvalid_operation,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2711 "replace-match called before any match found", Qunbound);
428
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 (NILP (string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714 {
469
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2715 if (search_regs.start[sub] < BUF_BEGV (buf)
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2716 || search_regs.start[sub] > search_regs.end[sub]
ccaeb2a3c329 [xemacs-hg @ 2001-04-13 15:04:38 by michaels]
michaels
parents: 462
diff changeset
2717 || search_regs.end[sub] > BUF_ZV (buf))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2718 args_out_of_range (make_fixnum (search_regs.start[sub]),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2719 make_fixnum (search_regs.end[sub]));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 if (search_regs.start[0] < 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 || 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
2725 || search_regs.end[0] > string_char_length (string))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2726 args_out_of_range (make_fixnum (search_regs.start[0]),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2727 make_fixnum (search_regs.end[0]));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 }
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 if (NILP (fixedcase))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 /* Decide how to casify by examining the matched text. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2734 last = search_regs.end[sub];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 prevc = '\n';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 case_action = all_caps;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 /* some_multiletter_word is set nonzero if any original word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739 is more than one letter long. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 some_multiletter_word = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 some_lowercase = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 some_nonuppercase_initial = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 some_uppercase = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2744
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2745 for (pos = search_regs.start[sub]; pos < last; pos++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 if (NILP (string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 c = BUF_FETCH_CHAR (buf, pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 else
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2750 c = string_ichar (string, pos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 if (LOWERCASEP (buf, c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 /* Cannot be all caps if any original char is lower case */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 some_lowercase = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2757 if (!WORD_SYNTAX_P (syntax_table, prevc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2758 some_nonuppercase_initial = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 some_multiletter_word = 1;
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 else if (!NOCASEP (buf, c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764 some_uppercase = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 if (!WORD_SYNTAX_P (syntax_table, prevc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 some_multiletter_word = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2770 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2771 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2772 /* If the initial is a caseless word constituent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 treat that like a lowercase initial. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 if (!WORD_SYNTAX_P (syntax_table, prevc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775 some_nonuppercase_initial = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 prevc = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 }
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 /* Convert to all caps if the old text is all caps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782 and has at least one multiletter word. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2783 if (! some_lowercase && some_multiletter_word)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784 case_action = all_caps;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785 /* Capitalize each word, if the old text has all capitalized words. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786 else if (!some_nonuppercase_initial && some_multiletter_word)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 case_action = cap_initial;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 else if (!some_nonuppercase_initial && some_uppercase)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 /* Should x -> yz, operating on X, give Yz or YZ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790 We'll assume the latter. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 case_action = all_caps;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 case_action = nochange;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 }
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 /* Do replacement in a string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797 if (!NILP (string))
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 Lisp_Object before, after;
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 speccount = specpdl_depth ();
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2802 before = Fsubseq (string, Qzero, make_fixnum (search_regs.start[sub]));
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2803 after = Fsubseq (string, make_fixnum (search_regs.end[sub]), Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2805 /* Do case substitution into REPLACEMENT if desired. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 if (NILP (literal))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2808 Charcount stlen = string_char_length (replacement);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 Charcount strpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 /* XEmacs change: rewrote this loop somewhat to make it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 cleaner. Also added \U, \E, etc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 Charcount literal_start = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 /* We build up the substituted string in ACCUM. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 Lisp_Object accum;
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 accum = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818 /* OK, the basic idea here is that we scan through the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819 replacement string until we find a backslash, which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 represents a substring of the original string to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 substituted. We then append onto ACCUM the literal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 text before the backslash (LASTPOS marks the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 beginning of this) followed by the substring of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 original string that needs to be inserted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 for (strpos = 0; strpos < stlen; strpos++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 /* If LITERAL_END is set, we've encountered a backslash
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 (the end of literal text to be inserted). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 Charcount literal_end = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 /* If SUBSTART is set, we need to also insert the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 text from SUBSTART to SUBEND in the original string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 Charcount substart = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 Charcount subend = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2835 c = string_ichar (replacement, strpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 if (c == '\\' && strpos < stlen - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2838 c = string_ichar (replacement, ++strpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 if (c == '&')
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 literal_end = strpos - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 substart = search_regs.start[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 subend = search_regs.end[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 }
4199
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2845 /* #### This logic is totally broken,
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
2846 since we can have backrefs like "\99", right? */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 else if (c >= '1' && c <= '9' &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 c <= search_regs.num_regs + '0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 if (search_regs.start[c - '0'] >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852 literal_end = strpos - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 substart = search_regs.start[c - '0'];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854 subend = search_regs.end[c - '0'];
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 else if (c == 'U' || c == 'u' || c == 'L' || c == 'l' ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 c == 'E')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 /* Keep track of all case changes requested, but don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 make them now. Do them later so we override
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 everything else. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 if (!ul_pos_dynarr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 ul_pos_dynarr = Dynarr_new (int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866 ul_action_dynarr = Dynarr_new (int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 record_unwind_protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 (free_created_dynarrs,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 noseeum_cons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 (make_opaque_ptr (ul_pos_dynarr),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 make_opaque_ptr (ul_action_dynarr)));
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 literal_end = strpos - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 Dynarr_add (ul_pos_dynarr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 (!NILP (accum)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2876 ? string_char_length (accum)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 : 0) + (literal_end - literal_start));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878 Dynarr_add (ul_action_dynarr, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 else if (c == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881 /* So we get just one backslash. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 literal_end = strpos;
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 if (literal_end >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 Lisp_Object literal_text = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 Lisp_Object substring = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 if (literal_end != literal_start)
5089
99f8ebc082d9 Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5041
diff changeset
2889 literal_text = Fsubseq (replacement,
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2890 make_fixnum (literal_start),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2891 make_fixnum (literal_end));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 if (substart >= 0 && subend != substart)
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2893 substring = Fsubseq (string, make_fixnum (substart),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2894 make_fixnum (subend));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 if (!NILP (literal_text) || !NILP (substring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 accum = concat3 (accum, literal_text, substring);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 literal_start = strpos + 1;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 if (strpos != literal_start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 /* some literal text at end to be inserted */
5089
99f8ebc082d9 Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5041
diff changeset
2903 replacement = concat2 (accum, Fsubseq (replacement,
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2904 make_fixnum (literal_start),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
2905 make_fixnum (strpos)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2907 replacement = accum;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2910 /* replacement can be nil. */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2911 if (NILP (replacement))
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4421
diff changeset
2912 replacement = build_ascstring ("");
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2913
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 if (case_action == all_caps)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2915 replacement = Fupcase (replacement, buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 else if (case_action == cap_initial)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2917 replacement = Fupcase_initials (replacement, buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 /* Now finally, we need to process the \U's, \E's, etc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 if (ul_pos_dynarr)
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 int i = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 int cur_action = 'E';
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2924 Charcount stlen = string_char_length (replacement);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 Charcount strpos;
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 for (strpos = 0; strpos < stlen; strpos++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2929 Ichar curchar = string_ichar (replacement, strpos);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2930 Ichar newchar = -1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 if (i < Dynarr_length (ul_pos_dynarr) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 strpos == Dynarr_at (ul_pos_dynarr, i))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 int new_action = Dynarr_at (ul_action_dynarr, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 if (new_action == 'u')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 newchar = UPCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938 else if (new_action == 'l')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 newchar = DOWNCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 cur_action = new_action;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 if (newchar == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 if (cur_action == 'U')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 newchar = UPCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 else if (cur_action == 'L')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 newchar = DOWNCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 newchar = curchar;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 if (newchar != curchar)
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
2953 set_string_char (replacement, strpos, newchar);
428
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 }
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 /* frees the Dynarrs if necessary. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2958 unbind_to (speccount);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2959 return concat3 (before, replacement, after);
428
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
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2962 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
2963 search_regs.end[sub]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 /* begin_multiple_change() records an unwind-protect, so we need to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 record this value now. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967 speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 /* We insert the replacement text before the old text, and then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970 delete the original text. This means that markers at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 beginning or end of the original will float to the corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972 position in the replacement. */
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2973 BUF_SET_PT (buf, search_regs.start[sub]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 if (!NILP (literal))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2975 Finsert (1, &replacement);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 814
diff changeset
2978 Charcount stlen = string_char_length (replacement);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 Charcount strpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 struct gcpro gcpro1;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2981 GCPRO1 (replacement);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 for (strpos = 0; strpos < stlen; strpos++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 {
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2984 /* on the first iteration assert(offset==0),
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2985 exactly complementing BUF_SET_PT() above.
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2986 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
2987 */
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2988 Charcount offset = BUF_PT (buf) - search_regs.start[sub];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2990 c = string_ichar (replacement, strpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 if (c == '\\' && strpos < stlen - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 {
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2993 /* XXX FIXME: replacing just a substring non-literally
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2994 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
2995 <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
2996 <duwe@caldera.de> claims Finsert_buffer_substring already
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2997 handles this correctly.
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
2998 */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
2999 c = string_ichar (replacement, ++strpos);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 if (c == '&')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 Finsert_buffer_substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 (buffer,
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3003 make_fixnum (search_regs.start[0] + offset),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3004 make_fixnum (search_regs.end[0] + offset));
4199
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
3005 /* #### This logic is totally broken,
3660d327399f [xemacs-hg @ 2007-10-01 08:07:39 by stephent]
stephent
parents: 2500
diff changeset
3006 since we can have backrefs like "\99", right? */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007 else if (c >= '1' && c <= '9' &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 c <= search_regs.num_regs + '0')
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 if (search_regs.start[c - '0'] >= 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 Finsert_buffer_substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 (buffer,
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3013 make_fixnum (search_regs.start[c - '0'] + offset),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3014 make_fixnum (search_regs.end[c - '0'] + offset));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 else if (c == 'U' || c == 'u' || c == 'L' || c == 'l' ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 c == 'E')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 /* Keep track of all case changes requested, but don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 make them now. Do them later so we override
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 everything else. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 if (!ul_pos_dynarr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 ul_pos_dynarr = Dynarr_new (int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 ul_action_dynarr = Dynarr_new (int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026 record_unwind_protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 (free_created_dynarrs,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 Fcons (make_opaque_ptr (ul_pos_dynarr),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 make_opaque_ptr (ul_action_dynarr)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 Dynarr_add (ul_pos_dynarr, BUF_PT (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 Dynarr_add (ul_action_dynarr, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 buffer_insert_emacs_char (buf, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 buffer_insert_emacs_char (buf, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3040 UNGCPRO;
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
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
3043 inslen = BUF_PT (buf) - (search_regs.start[sub]);
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 665
diff changeset
3044 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
3045 search_regs.end[sub] + inslen, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047 if (case_action == all_caps)
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3048 Fupcase_region (make_fixnum (BUF_PT (buf) - inslen),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3049 make_fixnum (BUF_PT (buf)), buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3050 else if (case_action == cap_initial)
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3051 Fupcase_initials_region (make_fixnum (BUF_PT (buf) - inslen),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3052 make_fixnum (BUF_PT (buf)), buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3053
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 /* Now go through and make all the case changes that were requested
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055 in the replacement string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056 if (ul_pos_dynarr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
3058 Charbpos eend = BUF_PT (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059 int i = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060 int cur_action = 'E';
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 for (pos = BUF_PT (buf) - inslen; pos < eend; pos++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
3064 Ichar curchar = BUF_FETCH_CHAR (buf, pos);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
3065 Ichar newchar = -1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 if (i < Dynarr_length (ul_pos_dynarr) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067 pos == Dynarr_at (ul_pos_dynarr, i))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3068 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069 int new_action = Dynarr_at (ul_action_dynarr, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070 i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3071 if (new_action == 'u')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3072 newchar = UPCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073 else if (new_action == 'l')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3074 newchar = DOWNCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 cur_action = new_action;
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 if (newchar == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 if (cur_action == 'U')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081 newchar = UPCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082 else if (cur_action == 'L')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 newchar = DOWNCASE (buf, curchar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3085 newchar = curchar;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3086 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3087 if (newchar != curchar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3088 buffer_replace_char (buf, pos, newchar, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3092 /* frees the Dynarrs if necessary. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
3093 unbind_to (speccount);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3094 end_multiple_change (buf, mc_count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3095
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3096 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3097 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 match_limit (Lisp_Object num, int beginningp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3102 int n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3103
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3104 CHECK_FIXNUM (num);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3105 n = XFIXNUM (num);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106 if (n < 0 || n >= search_regs.num_regs)
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3107 args_out_of_range (num, make_fixnum (search_regs.num_regs));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3108 if (search_regs.num_regs == 0 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3109 search_regs.start[n] < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 return Qnil;
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3111 return make_fixnum (beginningp ? search_regs.start[n] : search_regs.end[n]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3112 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114 DEFUN ("match-beginning", Fmatch_beginning, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115 Return position of start of text matched by last regexp search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116 NUM, specifies which parenthesized expression in the last regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3117 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
3118 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
3119 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120 (num))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3122 return match_limit (num, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 DEFUN ("match-end", Fmatch_end, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 Return position of end of text matched by last regexp search.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 NUM specifies which parenthesized expression in the last regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128 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
3129 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
3130 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 (num))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 return match_limit (num, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136 DEFUN ("match-data", Fmatch_data, 0, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137 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
3138 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
3139 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
3140 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
3141 Use `store-match-data' to reinstate the data in this list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 If INTEGERS (the optional first argument) is non-nil, always use integers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 \(rather than markers) to represent buffer positions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145 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
3146 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
3147 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3148 (integers, reuse))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150 Lisp_Object tail, prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151 Lisp_Object *data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153 Charcount len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155 if (NILP (last_thing_searched))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 507
diff changeset
3156 /*error ("match-data called before any match found", Qunbound);*/
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3157 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3159 data = alloca_array (Lisp_Object, 2 * search_regs.num_regs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161 len = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 for (i = 0; i < search_regs.num_regs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
3164 Charbpos start = search_regs.start[i];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3165 if (start >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167 if (EQ (last_thing_searched, Qt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 || !NILP (integers))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3169 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3170 data[2 * i] = make_fixnum (start);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3171 data[2 * i + 1] = make_fixnum (search_regs.end[i]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 else if (BUFFERP (last_thing_searched))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 data[2 * i] = Fmake_marker ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176 Fset_marker (data[2 * i],
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3177 make_fixnum (start),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 last_thing_searched);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179 data[2 * i + 1] = Fmake_marker ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180 Fset_marker (data[2 * i + 1],
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3181 make_fixnum (search_regs.end[i]),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3182 last_thing_searched);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185 /* last_thing_searched must always be Qt, a buffer, or Qnil. */
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2421
diff changeset
3186 ABORT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3188 len = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3189 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191 data[2 * i] = data [2 * i + 1] = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3192 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 if (!CONSP (reuse))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 return Flist (2 * len + 2, data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196 /* 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
3197 into the elements of REUSE. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198 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
3199 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 if (i < 2 * len + 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201 XCAR (tail) = data[i];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3202 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203 XCAR (tail) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204 prev = tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3207 /* If we couldn't fit all value elements into REUSE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3208 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
3209 if (i < 2 * len + 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210 XCDR (prev) = Flist (2 * len + 2 - i, data + i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 return reuse;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3215
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216 DEFUN ("store-match-data", Fstore_match_data, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 Set internal data on last search match from elements of LIST.
1468
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
3218 LIST should have been created by calling `match-data' previously,
0f42689481f0 [xemacs-hg @ 2003-05-09 14:52:37 by stephent]
stephent
parents: 1425
diff changeset
3219 or be nil, to clear the internal match data.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3220 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221 (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 REGISTER int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 REGISTER Lisp_Object marker;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225 int num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226 int length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3227
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3228 /* Some FSF junk with running_asynch_code, to preserve the match
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3229 data. Not necessary because we don't call process filters
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 851
diff changeset
3230 asynchronously (i.e. from within QUIT). */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 CONCHECK_LIST (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 /* 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
3235 match data came from a string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3236 last_thing_searched = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238 /* Allocate registers if they don't already exist. */
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3239 length = XFIXNUM (Flength (list)) / 2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240 num_regs = search_regs.num_regs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 if (length > num_regs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 if (search_regs.num_regs == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246 search_regs.start = xnew_array (regoff_t, length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 search_regs.end = xnew_array (regoff_t, length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 XREALLOC_ARRAY (search_regs.start, regoff_t, length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252 XREALLOC_ARRAY (search_regs.end, regoff_t, length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 search_regs.num_regs = length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258 for (i = 0; i < num_regs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 marker = Fcar (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 if (NILP (marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263 search_regs.start[i] = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264 list = Fcdr (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 if (MARKERP (marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270 if (XMARKER (marker)->buffer == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271 marker = Qzero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 else
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
3273 last_thing_searched = wrap_buffer (XMARKER (marker)->buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3276 CHECK_FIXNUM_COERCE_MARKER (marker);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3277 search_regs.start[i] = XFIXNUM (marker);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278 list = Fcdr (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280 marker = Fcar (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 if (MARKERP (marker) && XMARKER (marker)->buffer == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282 marker = Qzero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3284 CHECK_FIXNUM_COERCE_MARKER (marker);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5542
diff changeset
3285 search_regs.end[i] = XFIXNUM (marker);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287 list = Fcdr (list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293 /* Quote a string to inactivate reg-expr chars */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3295 DEFUN ("regexp-quote", Fregexp_quote, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3296 Return a regexp string which matches exactly STRING and nothing else.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3297 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3298 (string))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3299 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
3300 REGISTER Ibyte *in, *out, *end;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
3301 REGISTER Ibyte *temp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3302
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3303 CHECK_STRING (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3304
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2333
diff changeset
3305 temp = alloca_ibytes (XSTRING_LENGTH (string) * 2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 /* Now copy the data into the new string, inserting escapes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3309 in = XSTRING_DATA (string);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3310 end = in + XSTRING_LENGTH (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3311 out = temp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313 while (in < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
3315 Ichar c = itext_ichar (in);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3317 if (c == '[' || c == ']'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3318 || c == '*' || c == '.' || c == '\\'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3319 || c == '?' || c == '+'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320 || c == '^' || c == '$')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321 *out++ = '\\';
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
3322 out += set_itext_ichar (out, c);
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 853
diff changeset
3323 INC_IBYTEPTR (in);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326 return make_string (temp, out - temp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3329 DEFUN ("set-word-regexp", Fset_word_regexp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3330 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
3331 #### Not yet implemented. Currently does nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332 #### Do not use this yet. Its calling interface is likely to change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3333 */
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2268
diff changeset
3334 (UNUSED (regexp)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3335 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3336 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3337 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3339
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3340 #ifdef DEBUG_XEMACS
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3341
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3342 static int
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3343 debug_regexps_changed (Lisp_Object UNUSED (sym), Lisp_Object *val,
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3344 Lisp_Object UNUSED (in_object),
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3345 int UNUSED (flags))
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3346 {
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3347 int newval = 0;
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3348
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3349 EXTERNAL_LIST_LOOP_2 (elt, *val)
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3350 {
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3351 CHECK_SYMBOL (elt);
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3352 if (EQ (elt, Qcompilation))
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3353 newval |= RE_DEBUG_COMPILATION;
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3354 else if (EQ (elt, Qfailure_point))
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3355 newval |= RE_DEBUG_FAILURE_POINT;
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3356 else if (EQ (elt, Qmatching))
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3357 newval |= RE_DEBUG_MATCHING;
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3358 else
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3359 invalid_argument
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3360 ("Expected `compilation', `failure-point' or `matching'", elt);
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3361 }
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3362 debug_regexps = newval;
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3363 return 0;
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3364 }
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3365
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3366 #endif /* DEBUG_XEMACS */
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3367
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3368
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3369 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3370 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3371 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374 syms_of_search (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3375 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3376
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3377 DEFERROR_STANDARD (Qsearch_failed, Qinvalid_operation);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3378 DEFERROR_STANDARD (Qinvalid_regexp, Qsyntax_error);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 507
diff changeset
3379 Fput (Qinvalid_regexp, Qerror_lacks_explanatory_string, Qt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3381 DEFSUBR (Flooking_at);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382 DEFSUBR (Fposix_looking_at);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383 DEFSUBR (Fstring_match);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 DEFSUBR (Fposix_string_match);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385 DEFSUBR (Fskip_chars_forward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386 DEFSUBR (Fskip_chars_backward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3387 DEFSUBR (Fskip_syntax_forward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3388 DEFSUBR (Fskip_syntax_backward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3389 DEFSUBR (Fsearch_forward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3390 DEFSUBR (Fsearch_backward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3391 DEFSUBR (Fword_search_forward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392 DEFSUBR (Fword_search_backward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3393 DEFSUBR (Fre_search_forward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394 DEFSUBR (Fre_search_backward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 DEFSUBR (Fposix_search_forward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3396 DEFSUBR (Fposix_search_backward);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 DEFSUBR (Freplace_match);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398 DEFSUBR (Fmatch_beginning);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399 DEFSUBR (Fmatch_end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400 DEFSUBR (Fmatch_data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401 DEFSUBR (Fstore_match_data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 DEFSUBR (Fregexp_quote);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3403 DEFSUBR (Fset_word_regexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407 reinit_vars_of_search (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 last_thing_searched = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412 staticpro_nodump (&last_thing_searched);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414 for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416 searchbufs[i].buf.allocated = 100;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417 searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418 searchbufs[i].buf.fastmap = searchbufs[i].fastmap;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3419 searchbufs[i].regexp = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420 staticpro_nodump (&searchbufs[i].regexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3421 searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3422 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 searchbuf_head = &searchbufs[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427 vars_of_search (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429 DEFVAR_LISP ("forward-word-regexp", &Vforward_word_regexp /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430 *Regular expression to be used in `forward-word'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 #### Not yet implemented.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433 Vforward_word_regexp = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435 DEFVAR_LISP ("backward-word-regexp", &Vbackward_word_regexp /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436 *Regular expression to be used in `backward-word'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437 #### Not yet implemented.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439 Vbackward_word_regexp = Qnil;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3440
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3441 DEFVAR_INT ("warn-about-possibly-incompatible-back-references",
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3442 &warn_about_possibly_incompatible_back_references /*
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3443 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
3444 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
3445 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
3446 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
3447 */ );
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 469
diff changeset
3448 warn_about_possibly_incompatible_back_references = 1;
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 793
diff changeset
3449
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
3450 Vskip_chars_range_table = Fmake_range_table (Qstart_closed_end_closed);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451 staticpro (&Vskip_chars_range_table);
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
3452 #ifdef DEBUG_XEMACS
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
3453 DEFSYMBOL (Qsearch_algorithm_used);
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
3454 DEFSYMBOL (Qboyer_moore);
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
3455 DEFSYMBOL (Qsimple_search);
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
3456
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3457 DEFSYMBOL (Qcompilation);
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3458 DEFSYMBOL (Qfailure_point);
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3459 DEFSYMBOL (Qmatching);
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3460
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3461 DEFVAR_INT ("debug-searches", &debug_searches /*
4414
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
3462 If non-zero, bind `search-algorithm-used' to `boyer-moore' or `simple-search',
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
3463 depending on the algorithm used for each search. Used for testing.
df576f30c1d8 Correct case-insensitive search for non-case, non-ASCII chars. Add tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4407
diff changeset
3464 */ );
5041
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3465 debug_searches = 0;
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3466
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3467 DEFVAR_LISP_MAGIC ("debug-regexps", &Vdebug_regexps, /*
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3468 List of areas to display debug info about during regexp operation.
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3469 The following areas are recognized:
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3470
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3471 `compilation' Display the result of compiling a regexp.
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3472 `failure-point' Display info about failure points reached.
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3473 `matching' Display info about the process of matching a regex against
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3474 text.
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3475 */ debug_regexps_changed);
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3476 Vdebug_regexps = Qnil;
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3477 debug_regexps = 0;
efaa6cd845e5 add regexp-debugging
Ben Wing <ben@xemacs.org>
parents: 5016
diff changeset
3478 #endif /* DEBUG_XEMACS */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3479 }