X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fsearch.c;h=97ae5e162c4c2a8b3829bc3821a3f8d5c35b96fc;hb=8ff16de3304e96abcc107b97d962d1b8bdd6c98f;hp=8a496cb3dec65d30b83f5bb46fa784eef2aa3f90;hpb=dbf2768f7b146e97e37a27316f70bb313f1acf15;p=chise%2Fxemacs-chise.git- diff --git a/src/search.c b/src/search.c index 8a496cb..97ae5e1 100644 --- a/src/search.c +++ b/src/search.c @@ -1,6 +1,7 @@ /* String search routines for XEmacs. Copyright (C) 1985, 1986, 1987, 1992-1995 Free Software Foundation, Inc. Copyright (C) 1995 Sun Microsystems, Inc. + Copyright (C) 1999,2000,2001 MORIOKA Tomohiko This file is part of XEmacs. @@ -108,6 +109,7 @@ Lisp_Object Vforward_word_regexp, Vbackward_word_regexp; Lisp_Object Vskip_chars_range_table; static void set_search_regs (struct buffer *buf, Bufpos beg, Charcount len); +static void clear_unused_search_regs (struct re_registers *regp, int no_sub); /* #### according to comment in 21.5, unnecessary */ static void save_search_regs (void); static Bufpos simple_search (struct buffer *buf, Bufbyte *base_pat, @@ -787,8 +789,12 @@ skip_chars (struct buffer *buf, int forwardp, int syntaxp, int negate = 0; REGISTER int i; #ifndef emacs +#ifdef UTF2000 + Lisp_Char_Table *syntax_table = XCHAR_TABLE (buf->syntax_table); +#else Lisp_Char_Table *syntax_table = XCHAR_TABLE (buf->mirror_syntax_table); #endif +#endif Bufpos limit; if (NILP (lim)) @@ -1114,6 +1120,7 @@ trivial_regexp_p (Lisp_Object regexp) { switch (*s++) { + /* ']' doesn't appear here because it's only special after ] */ case '.': case '*': case '+': case '?': case '[': case '^': case '$': return 0; case '\\': @@ -1123,7 +1130,7 @@ trivial_regexp_p (Lisp_Object regexp) { case '|': case '(': case ')': case '`': case '\'': case 'b': case 'B': case '<': case '>': case 'w': case 'W': case 's': - case 'S': case '=': + case 'S': case '=': case '{': case '}': #ifdef MULE /* 97/2/25 jhod Added for category matches */ case 'c': case 'C': @@ -1173,10 +1180,11 @@ search_buffer (struct buffer *buf, Lisp_Object string, Bufpos bufpos, if (len == 0) { set_search_regs (buf, bufpos, 0); + clear_unused_search_regs (&search_regs, 0); return bufpos; } - /* Searching 0 times means don't move. */ + /* Searching 0 times means noop---don't move, don't touch registers. */ if (n == 0) return bufpos; @@ -1223,6 +1231,8 @@ search_buffer (struct buffer *buf, Lisp_Object string, Bufpos bufpos, search_regs.start[i] += j; search_regs.end[i] += j; } + /* re_match (called from re_search et al) does this for us */ + /* clear_unused_search_regs (search_regs, bufp->no_sub); */ XSETBUFFER (last_thing_searched, buf); /* Set pos to the new position. */ pos = search_regs.start[0]; @@ -1260,6 +1270,8 @@ search_buffer (struct buffer *buf, Lisp_Object string, Bufpos bufpos, search_regs.start[i] += j; search_regs.end[i] += j; } + /* re_match (called from re_search et al) does this for us */ + /* clear_unused_search_regs (search_regs, bufp->no_sub); */ XSETBUFFER (last_thing_searched, buf); /* Set pos to the new position. */ pos = search_regs.end[0]; @@ -1312,7 +1324,11 @@ search_buffer (struct buffer *buf, Lisp_Object string, Bufpos bufpos, { /* Keep track of which character set row contains the characters that need translation. */ +#ifdef UTF2000 + int charset_base_code = c >> 6; +#else int charset_base_code = c & ~CHAR_FIELD3_MASK; +#endif if (charset_base == -1) charset_base = charset_base_code; else if (charset_base != charset_base_code) @@ -1460,6 +1476,7 @@ simple_search (struct buffer *buf, Bufbyte *base_pat, Bytecount len_byte, end = bytind_to_bufpos (buf, idx + buf_len); } set_search_regs (buf, beg, end - beg); + clear_unused_search_regs (&search_regs, 0); return retval; } @@ -1611,7 +1628,11 @@ boyer_moore (struct buffer *buf, Bufbyte *base_pat, Bytecount len, while (!BUFBYTE_FIRST_BYTE_P (*charstart)) charstart--; untranslated = charptr_emchar (charstart); +#ifdef UTF2000 + if (charset_base == (untranslated >> 6)) +#else if (charset_base == (untranslated & ~CHAR_FIELD3_MASK)) +#endif { ch = TRANSLATE (trt, untranslated); if (!BUFBYTE_FIRST_BYTE_P (*ptr)) @@ -1821,6 +1842,7 @@ boyer_moore (struct buffer *buf, Bufbyte *base_pat, Bytecount len, Bufpos bufend = bytind_to_bufpos (buf, bytstart + len); set_search_regs (buf, bufstart, bufend - bufstart); + clear_unused_search_regs (&search_regs, 0); } if ((n -= direction) != 0) @@ -1910,6 +1932,7 @@ boyer_moore (struct buffer *buf, Bufbyte *base_pat, Bytecount len, Bufpos bufend = bytind_to_bufpos (buf, bytstart + len); set_search_regs (buf, bufstart, bufend - bufstart); + clear_unused_search_regs (&search_regs, 0); } if ((n -= direction) != 0) @@ -1929,8 +1952,8 @@ boyer_moore (struct buffer *buf, Bufbyte *base_pat, Bytecount len, return bytind_to_bufpos (buf, pos); } -/* Record beginning BEG and end BEG + LEN - for a match just found in the current buffer. */ +/* Record the whole-match data (beginning BEG and end BEG + LEN) and the + buffer for a match just found. */ static void set_search_regs (struct buffer *buf, Bufpos beg, Charcount len) @@ -1950,6 +1973,24 @@ set_search_regs (struct buffer *buf, Bufpos beg, Charcount len) XSETBUFFER (last_thing_searched, buf); } +/* Clear unused search registers so match data will be null. + REGP is a pointer to the register structure to clear, usually the global + search_regs. + NO_SUB is the number of subexpressions to allow for. (Does not count + the whole match, ie, for a string search NO_SUB == 0.) + It is an error if NO_SUB > REGP.num_regs - 1. */ + +static void +clear_unused_search_regs (struct re_registers *regp, int no_sub) +{ + /* This function has been Mule-ized. */ + int i; + + assert (no_sub >= 0 && no_sub < regp->num_regs); + for (i = no_sub + 1; i < regp->num_regs; i++) + regp->start[i] = regp->end[i] = -1; +} + /* Given a string of words separated by word delimiters, compute a regexp that matches those exact words @@ -1961,7 +2002,11 @@ wordify (Lisp_Object buffer, Lisp_Object string) Charcount i, len; EMACS_INT punct_count = 0, word_count = 0; struct buffer *buf = decode_buffer (buffer, 0); +#ifdef UTF2000 + Lisp_Char_Table *syntax_table = XCHAR_TABLE (buf->syntax_table); +#else Lisp_Char_Table *syntax_table = XCHAR_TABLE (buf->mirror_syntax_table); +#endif CHECK_STRING (string); len = XSTRING_CHAR_LENGTH (string); @@ -2330,7 +2375,11 @@ match since only regular expressions have distinguished subexpressions. buf = XBUFFER (buffer); } +#ifdef UTF2000 + syntax_table = XCHAR_TABLE (buf->syntax_table); +#else syntax_table = XCHAR_TABLE (buf->mirror_syntax_table); +#endif case_action = nochange; /* We tried an initialization */ /* but some C compilers blew it */