aboutsummaryrefslogtreecommitdiffstats
path: root/src/search.c
diff options
context:
space:
mode:
authorJim Blandy1992-05-18 08:14:41 +0000
committerJim Blandy1992-05-18 08:14:41 +0000
commitffd56f97cf56501f7a6981c184192e9043e4eafd (patch)
treed463f4585c85fa76b33d3663271bbb4126d7b116 /src/search.c
parent502ddf238f0ed280a301426804b2ed16ec1c49cc (diff)
downloademacs-ffd56f97cf56501f7a6981c184192e9043e4eafd.tar.gz
emacs-ffd56f97cf56501f7a6981c184192e9043e4eafd.zip
*** empty log message ***
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c80
1 files changed, 47 insertions, 33 deletions
diff --git a/src/search.c b/src/search.c
index 9ac63aea874..5f1f17f2d53 100644
--- a/src/search.c
+++ b/src/search.c
@@ -210,80 +210,94 @@ matched by parenthesis constructs in the pattern.")
210 return make_number (val); 210 return make_number (val);
211} 211}
212 212
213scan_buffer (target, pos, cnt, shortage) 213/* Search for COUNT instances of the character TARGET, starting at START.
214 int *shortage, pos; 214 If COUNT is negative, search backwards.
215 register int cnt, target; 215
216 If we find COUNT instances, set *SHORTAGE to zero, and return the
217 position of the COUNTth character.
218
219 If we don't find COUNT instances before reaching the end of the
220 buffer (or the beginning, if scanning backwards), set *SHORTAGE to
221 the number of TARGETs left unfound, and return the end of the
222 buffer we bumped up against. */
223
224scan_buffer (target, start, count, shortage)
225 int *shortage, start;
226 register int count, target;
216{ 227{
217 int lim = ((cnt > 0) ? ZV - 1 : BEGV); 228 int limit = ((count > 0) ? ZV - 1 : BEGV);
218 int direction = ((cnt > 0) ? 1 : -1); 229 int direction = ((count > 0) ? 1 : -1);
219 register int lim0; 230
231 register unsigned char *cursor;
220 unsigned char *base; 232 unsigned char *base;
221 register unsigned char *cursor, *limit; 233
234 register int ceiling;
235 register unsigned char *ceiling_addr;
222 236
223 if (shortage != 0) 237 if (shortage != 0)
224 *shortage = 0; 238 *shortage = 0;
225 239
226 immediate_quit = 1; 240 immediate_quit = 1;
227 241
228 if (cnt > 0) 242 if (count > 0)
229 while (pos != lim + 1) 243 while (start != limit + 1)
230 { 244 {
231 lim0 = BUFFER_CEILING_OF (pos); 245 ceiling = BUFFER_CEILING_OF (start);
232 lim0 = min (lim, lim0); 246 ceiling = min (limit, ceiling);
233 limit = &FETCH_CHAR (lim0) + 1; 247 ceiling_addr = &FETCH_CHAR (ceiling) + 1;
234 base = (cursor = &FETCH_CHAR (pos)); 248 base = (cursor = &FETCH_CHAR (start));
235 while (1) 249 while (1)
236 { 250 {
237 while (*cursor != target && ++cursor != limit) 251 while (*cursor != target && ++cursor != ceiling_addr)
238 ; 252 ;
239 if (cursor != limit) 253 if (cursor != ceiling_addr)
240 { 254 {
241 if (--cnt == 0) 255 if (--count == 0)
242 { 256 {
243 immediate_quit = 0; 257 immediate_quit = 0;
244 return (pos + cursor - base + 1); 258 return (start + cursor - base + 1);
245 } 259 }
246 else 260 else
247 if (++cursor == limit) 261 if (++cursor == ceiling_addr)
248 break; 262 break;
249 } 263 }
250 else 264 else
251 break; 265 break;
252 } 266 }
253 pos += cursor - base; 267 start += cursor - base;
254 } 268 }
255 else 269 else
256 { 270 {
257 pos--; /* first character we scan */ 271 start--; /* first character we scan */
258 while (pos > lim - 1) 272 while (start > limit - 1)
259 { /* we WILL scan under pos */ 273 { /* we WILL scan under start */
260 lim0 = BUFFER_FLOOR_OF (pos); 274 ceiling = BUFFER_FLOOR_OF (start);
261 lim0 = max (lim, lim0); 275 ceiling = max (limit, ceiling);
262 limit = &FETCH_CHAR (lim0) - 1; 276 ceiling_addr = &FETCH_CHAR (ceiling) - 1;
263 base = (cursor = &FETCH_CHAR (pos)); 277 base = (cursor = &FETCH_CHAR (start));
264 cursor++; 278 cursor++;
265 while (1) 279 while (1)
266 { 280 {
267 while (--cursor != limit && *cursor != target) 281 while (--cursor != ceiling_addr && *cursor != target)
268 ; 282 ;
269 if (cursor != limit) 283 if (cursor != ceiling_addr)
270 { 284 {
271 if (++cnt == 0) 285 if (++count == 0)
272 { 286 {
273 immediate_quit = 0; 287 immediate_quit = 0;
274 return (pos + cursor - base + 1); 288 return (start + cursor - base + 1);
275 } 289 }
276 } 290 }
277 else 291 else
278 break; 292 break;
279 } 293 }
280 pos += cursor - base; 294 start += cursor - base;
281 } 295 }
282 } 296 }
283 immediate_quit = 0; 297 immediate_quit = 0;
284 if (shortage != 0) 298 if (shortage != 0)
285 *shortage = cnt * direction; 299 *shortage = count * direction;
286 return (pos + ((direction == 1 ? 0 : 1))); 300 return (start + ((direction == 1 ? 0 : 1)));
287} 301}
288 302
289int 303int