comparison src/search.c @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents 376386a54a3c
children 859a2309aef8
comparison
equal deleted inserted replaced
15:ad457d5f7d04 16:0293115a14e9
131 cp->buf.translate = translate; 131 cp->buf.translate = translate;
132 cp->posix = posix; 132 cp->posix = posix;
133 old = re_set_syntax (RE_SYNTAX_EMACS 133 old = re_set_syntax (RE_SYNTAX_EMACS
134 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING)); 134 | (posix ? 0 : RE_NO_POSIX_BACKTRACKING));
135 val = (CONST char *) 135 val = (CONST char *)
136 re_compile_pattern ((char *) string_data (XSTRING (pattern)), 136 re_compile_pattern ((char *) XSTRING_DATA (pattern),
137 string_length (XSTRING (pattern)), &cp->buf); 137 XSTRING_LENGTH (pattern), &cp->buf);
138 re_set_syntax (old); 138 re_set_syntax (old);
139 if (val) 139 if (val)
140 { 140 {
141 maybe_signal_error (Qinvalid_regexp, list1 (build_string (val)), 141 maybe_signal_error (Qinvalid_regexp, list1 (build_string (val)),
142 Qsearch, errb); 142 Qsearch, errb);
246 for (i = 0; i < search_regs.num_regs; i++) 246 for (i = 0; i < search_regs.num_regs; i++)
247 { 247 {
248 if (search_regs.start[i] > 0) 248 if (search_regs.start[i] > 0)
249 { 249 {
250 search_regs.start[i] = 250 search_regs.start[i] =
251 bytecount_to_charcount (string_data (XSTRING (string)), 251 bytecount_to_charcount (XSTRING_DATA (string),
252 search_regs.start[i]); 252 search_regs.start[i]);
253 } 253 }
254 if (search_regs.end[i] > 0) 254 if (search_regs.end[i] > 0)
255 { 255 {
256 search_regs.end[i] = 256 search_regs.end[i] =
257 bytecount_to_charcount (string_data (XSTRING (string)), 257 bytecount_to_charcount (XSTRING_DATA (string),
258 search_regs.end[i]); 258 search_regs.end[i]);
259 } 259 }
260 } 260 }
261 } 261 }
262 262
377 (!NILP (buf->case_fold_search) 377 (!NILP (buf->case_fold_search)
378 ? (char *) MIRROR_DOWNCASE_TABLE_AS_STRING (buf) 378 ? (char *) MIRROR_DOWNCASE_TABLE_AS_STRING (buf)
379 : 0), 0, ERROR_ME); 379 : 0), 0, ERROR_ME);
380 QUIT; 380 QUIT;
381 { 381 {
382 Bytecount bis = charcount_to_bytecount (string_data (XSTRING (string)), 382 Bytecount bis = charcount_to_bytecount (XSTRING_DATA (string), s);
383 s);
384 regex_emacs_buffer = buf; 383 regex_emacs_buffer = buf;
385 val = re_search (bufp, (char *) string_data (XSTRING (string)), 384 val = re_search (bufp, (char *) XSTRING_DATA (string),
386 string_length (XSTRING (string)), bis, 385 XSTRING_LENGTH (string), bis,
387 string_length (XSTRING (string)) - bis, 386 XSTRING_LENGTH (string) - bis,
388 &search_regs); 387 &search_regs);
389 } 388 }
390 if (val == -2) 389 if (val == -2)
391 matcher_overflow (); 390 matcher_overflow ();
392 if (val < 0) return Qnil; 391 if (val < 0) return Qnil;
393 last_thing_searched = Qt; 392 last_thing_searched = Qt;
394 fixup_search_regs_for_string (string); 393 fixup_search_regs_for_string (string);
395 return make_int (bytecount_to_charcount (string_data (XSTRING (string)), 394 return make_int (bytecount_to_charcount (XSTRING_DATA (string), val));
396 val));
397 } 395 }
398 396
399 DEFUN ("string-match", Fstring_match, Sstring_match, 2, 4, 0 /* 397 DEFUN ("string-match", Fstring_match, Sstring_match, 2, 4, 0 /*
400 Return index of start of first match for REGEXP in STRING, or nil. 398 Return index of start of first match for REGEXP in STRING, or nil.
401 If third arg START is non-nil, start search at that index in STRING. 399 If third arg START is non-nil, start search at that index in STRING.
408 tables) and defaults to the current buffer. 406 tables) and defaults to the current buffer.
409 */ ) 407 */ )
410 (regexp, string, start, buffer) 408 (regexp, string, start, buffer)
411 Lisp_Object regexp, string, start, buffer; 409 Lisp_Object regexp, string, start, buffer;
412 { 410 {
413 return string_match_1 (regexp, string, start, decode_buffer (buffer, 0), 411 return string_match_1 (regexp, string, start, decode_buffer (buffer, 0), 0);
414 0);
415 } 412 }
416 413
417 DEFUN ("posix-string-match", Fposix_string_match, Sposix_string_match, 2, 4, 0 /* 414 DEFUN ("posix-string-match", Fposix_string_match, Sposix_string_match, 2, 4, 0 /*
418 Return index of start of first match for REGEXP in STRING, or nil. 415 Return index of start of first match for REGEXP in STRING, or nil.
419 Find the longest match, in accord with Posix regular expression rules. 416 Find the longest match, in accord with Posix regular expression rules.
427 tables) and defaults to the current buffer. 424 tables) and defaults to the current buffer.
428 */ ) 425 */ )
429 (regexp, string, start, buffer) 426 (regexp, string, start, buffer)
430 Lisp_Object regexp, string, start, buffer; 427 Lisp_Object regexp, string, start, buffer;
431 { 428 {
432 return string_match_1 (regexp, string, start, decode_buffer (buffer, 0), 429 return string_match_1 (regexp, string, start, decode_buffer (buffer, 0), 1);
433 1);
434 } 430 }
435 431
436 /* Match REGEXP against STRING, searching all of STRING, 432 /* Match REGEXP against STRING, searching all of STRING,
437 and return the index of the match, or negative on failure. 433 and return the index of the match, or negative on failure.
438 This does not clobber the match data. */ 434 This does not clobber the match data. */
465 fixup_internal_substring (nonreloc, reloc, offset, &length); 461 fixup_internal_substring (nonreloc, reloc, offset, &length);
466 462
467 if (!NILP (reloc)) 463 if (!NILP (reloc))
468 { 464 {
469 if (no_quit) 465 if (no_quit)
470 newnonreloc = string_data (XSTRING (reloc)); 466 newnonreloc = XSTRING_DATA (reloc);
471 else 467 else
472 { 468 {
473 /* QUIT could relocate RELOC. Therefore we must alloca() 469 /* QUIT could relocate RELOC. Therefore we must alloca()
474 and copy. No way around this except some serious 470 and copy. No way around this except some serious
475 rewriting of re_search(). */ 471 rewriting of re_search(). */
476 newnonreloc = (Bufbyte *) alloca (length); 472 newnonreloc = (Bufbyte *) alloca (length);
477 memcpy (newnonreloc, string_data (XSTRING (reloc)), length); 473 memcpy (newnonreloc, XSTRING_DATA (reloc), length);
478 } 474 }
479 } 475 }
480 476
481 /* #### evil current-buffer dependency */ 477 /* #### evil current-buffer dependency */
482 regex_emacs_buffer = current_buffer; 478 regex_emacs_buffer = current_buffer;
707 if (XINT (lim) > BUF_ZV (buf)) 703 if (XINT (lim) > BUF_ZV (buf))
708 lim = make_int (BUF_ZV (buf)); 704 lim = make_int (BUF_ZV (buf));
709 if (XINT (lim) < BUF_BEGV (buf)) 705 if (XINT (lim) < BUF_BEGV (buf))
710 lim = make_int (BUF_BEGV (buf)); 706 lim = make_int (BUF_BEGV (buf));
711 707
712 p = string_data (XSTRING (string)); 708 p = XSTRING_DATA (string);
713 pend = p + string_length (XSTRING (string)); 709 pend = p + XSTRING_LENGTH (string);
714 memset (fastmap, 0, sizeof (fastmap)); 710 memset (fastmap, 0, sizeof (fastmap));
715 711
716 Fclear_range_table (Vskip_chars_range_table); 712 Fclear_range_table (Vskip_chars_range_table);
717 713
718 if (p != pend && *p == '^') 714 if (p != pend && *p == '^')
983 979
984 static int 980 static int
985 trivial_regexp_p (Lisp_Object regexp) 981 trivial_regexp_p (Lisp_Object regexp)
986 { 982 {
987 /* This function has been Mule-ized. */ 983 /* This function has been Mule-ized. */
988 Bytecount len = string_length (XSTRING (regexp)); 984 Bytecount len = XSTRING_LENGTH (regexp);
989 Bufbyte *s = string_data (XSTRING (regexp)); 985 Bufbyte *s = XSTRING_DATA (regexp);
990 while (--len >= 0) 986 while (--len >= 0)
991 { 987 {
992 switch (*s++) 988 switch (*s++)
993 { 989 {
994 case '.': case '*': case '+': case '?': case '[': case '^': case '$': 990 case '.': case '*': case '+': case '?': case '[': case '^': case '$':
1031 search_buffer (struct buffer *buf, Lisp_Object string, Bufpos bufpos, 1027 search_buffer (struct buffer *buf, Lisp_Object string, Bufpos bufpos,
1032 Bufpos buflim, EMACS_INT n, int RE, unsigned char *trt, 1028 Bufpos buflim, EMACS_INT n, int RE, unsigned char *trt,
1033 unsigned char *inverse_trt, int posix) 1029 unsigned char *inverse_trt, int posix)
1034 { 1030 {
1035 /* This function has been Mule-ized, except for the trt table handling. */ 1031 /* This function has been Mule-ized, except for the trt table handling. */
1036 Bytecount len = string_length (XSTRING (string)); 1032 Bytecount len = XSTRING_LENGTH (string);
1037 Bufbyte *base_pat = string_data (XSTRING (string)); 1033 Bufbyte *base_pat = XSTRING_DATA (string);
1038 register EMACS_INT *BM_tab; 1034 register EMACS_INT *BM_tab;
1039 EMACS_INT *BM_tab_base; 1035 EMACS_INT *BM_tab_base;
1040 register int direction = ((n > 0) ? 1 : -1); 1036 register int direction = ((n > 0) ? 1 : -1);
1041 register Bytecount dirlen; 1037 register Bytecount dirlen;
1042 EMACS_INT infinity; 1038 EMACS_INT infinity;
1523 1519
1524 { 1520 {
1525 /* The following value is an upper bound on the amount of storage we 1521 /* The following value is an upper bound on the amount of storage we
1526 need. In non-Mule, it is exact. */ 1522 need. In non-Mule, it is exact. */
1527 Bufbyte *storage = 1523 Bufbyte *storage =
1528 (Bufbyte *) alloca (string_length (XSTRING (string)) - punct_count + 1524 (Bufbyte *) alloca (XSTRING_LENGTH (string) - punct_count +
1529 5 * (word_count - 1) + 4); 1525 5 * (word_count - 1) + 4);
1530 Bufbyte *o = storage; 1526 Bufbyte *o = storage;
1531 1527
1532 *o++ = '\\'; 1528 *o++ = '\\';
1533 *o++ = 'b'; 1529 *o++ = 'b';
2423 register Bufbyte *in, *out, *end; 2419 register Bufbyte *in, *out, *end;
2424 register Bufbyte *temp; 2420 register Bufbyte *temp;
2425 2421
2426 CHECK_STRING (str); 2422 CHECK_STRING (str);
2427 2423
2428 temp = (Bufbyte *) alloca (string_length (XSTRING (str)) * 2); 2424 temp = (Bufbyte *) alloca (XSTRING_LENGTH (str) * 2);
2429 2425
2430 /* Now copy the data into the new string, inserting escapes. */ 2426 /* Now copy the data into the new string, inserting escapes. */
2431 2427
2432 in = string_data (XSTRING (str)); 2428 in = XSTRING_DATA (str);
2433 end = in + string_length (XSTRING (str)); 2429 end = in + XSTRING_LENGTH (str);
2434 out = temp; 2430 out = temp;
2435 2431
2436 for (; in != end; in++) 2432 for (; in != end; in++)
2437 { 2433 {
2438 if (*in == '[' || *in == ']' 2434 if (*in == '[' || *in == ']'