Sync with r21_2_36.
[chise/xemacs-chise.git] / src / search.c
index 445bd87..7f92765 100644 (file)
@@ -54,10 +54,10 @@ struct regexp_cache {
 };
 
 /* The instances of that struct.  */
-struct regexp_cache searchbufs[REGEXP_CACHE_SIZE];
+static struct regexp_cache searchbufs[REGEXP_CACHE_SIZE];
 
 /* The head of the linked list; points to the most recently used buffer.  */
-struct regexp_cache *searchbuf_head;
+static struct regexp_cache *searchbuf_head;
 
 
 /* Every call to re_match, etc., must pass &search_regs as the regs
@@ -131,7 +131,7 @@ compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
                   char *translate, struct re_registers *regp, int posix,
                   Error_behavior errb)
 {
-  CONST char *val;
+  const char *val;
   reg_syntax_t old;
 
   cp->regexp = Qnil;
@@ -139,7 +139,7 @@ compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
   cp->posix = posix;
   old = re_set_syntax (RE_SYNTAX_EMACS
                       | (posix ? 0 : RE_NO_POSIX_BACKTRACKING));
-  val = (CONST char *)
+  val = (const char *)
     re_compile_pattern ((char *) XSTRING_DATA (pattern),
                        XSTRING_LENGTH (pattern), &cp->buf);
   re_set_syntax (old);
@@ -301,6 +301,7 @@ looking_at_1 (Lisp_Object string, struct buffer *buf, int posix)
   s2 = BI_BUF_ZV (buf) - p2;
 
   regex_emacs_buffer = buf;
+  regex_emacs_buffer_p = 1;
   i = re_match_2 (bufp, (char *) BI_BUF_BYTE_ADDRESS (buf, p1),
                  s1, (char *) BI_BUF_BYTE_ADDRESS (buf, p2), s2,
                  BI_BUF_PT (buf) - BI_BUF_BEGV (buf), &search_regs,
@@ -391,6 +392,7 @@ string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start,
   {
     Bytecount bis = charcount_to_bytecount (XSTRING_DATA (string), s);
     regex_emacs_buffer = buf;
+    regex_emacs_buffer_p = 0;
     val = re_search (bufp, (char *) XSTRING_DATA (string),
                     XSTRING_LENGTH (string), bis,
                     XSTRING_LENGTH (string) - bis,
@@ -442,7 +444,7 @@ tables) and defaults to the current buffer.
    This does not clobber the match data. */
 
 Bytecount
-fast_string_match (Lisp_Object regexp,  CONST Bufbyte *nonreloc,
+fast_string_match (Lisp_Object regexp,  const Bufbyte *nonreloc,
                   Lisp_Object reloc, Bytecount offset,
                   Bytecount length, int case_fold_search,
                   Error_behavior errb, int no_quit)
@@ -484,6 +486,7 @@ fast_string_match (Lisp_Object regexp,  CONST Bufbyte *nonreloc,
 
   /* #### evil current-buffer dependency */
   regex_emacs_buffer = current_buffer;
+  regex_emacs_buffer_p = 0;
   val = re_search (bufp, (char *) newnonreloc + offset, length, 0,
                   length, 0);
 
@@ -701,7 +704,7 @@ find_next_newline (struct buffer *buf, Bufpos from, int count)
 }
 
 Bytind
-bi_find_next_emchar_in_string (struct Lisp_String* str, Emchar target, Bytind st,
+bi_find_next_emchar_in_string (Lisp_String* str, Emchar target, Bytind st,
                               EMACS_INT count)
 {
   /* This function has been Mule-ized. */
@@ -771,8 +774,7 @@ skip_chars (struct buffer *buf, int forwardp, int syntaxp,
   unsigned char fastmap[0400];
   int negate = 0;
   REGISTER int i;
-  struct Lisp_Char_Table *syntax_table =
-    XCHAR_TABLE (buf->mirror_syntax_table);
+  Lisp_Char_Table *syntax_table = XCHAR_TABLE (buf->mirror_syntax_table);
   Bufpos limit;
 
   if (NILP (lim))
@@ -1165,6 +1167,7 @@ search_buffer (struct buffer *buf, Lisp_Object string, Bufpos bufpos,
          Bytecount val;
          QUIT;
           regex_emacs_buffer = buf;
+         regex_emacs_buffer_p = 1;
          val = re_search_2 (bufp,
                             (char *) BI_BUF_BYTE_ADDRESS (buf, p1), s1,
                             (char *) BI_BUF_BYTE_ADDRESS (buf, p2), s2,
@@ -1203,6 +1206,7 @@ search_buffer (struct buffer *buf, Lisp_Object string, Bufpos bufpos,
          Bytecount val;
          QUIT;
           regex_emacs_buffer = buf;
+         regex_emacs_buffer_p = 1;
           val = re_search_2 (bufp,
                             (char *) BI_BUF_BYTE_ADDRESS (buf, p1), s1,
                             (char *) BI_BUF_BYTE_ADDRESS (buf, p2), s2,
@@ -1243,7 +1247,7 @@ search_buffer (struct buffer *buf, Lisp_Object string, Bufpos bufpos,
 
        BTW "BM" stands for Boyer-Moore, which is one of the standard
        string-searching algorithms.  It's the best string-searching
-       algorithm out there provided
+       algorithm out there, provided that:
 
        a) You're not fazed by algorithm complexity. (Rabin-Karp, which
           uses hashing, is much much easier to code but not as fast.)
@@ -1575,8 +1579,8 @@ set_search_regs (struct buffer *buf, Bufpos beg, Charcount len)
 
 \f
 /* Given a string of words separated by word delimiters,
-  compute a regexp that matches those exact words
-  separated by arbitrary punctuation.  */
+   compute a regexp that matches those exact words
+   separated by arbitrary punctuation.  */
 
 static Lisp_Object
 wordify (Lisp_Object buffer, Lisp_Object string)
@@ -1584,8 +1588,7 @@ 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);
-  struct Lisp_Char_Table *syntax_table =
-    XCHAR_TABLE (buf->mirror_syntax_table);
+  Lisp_Char_Table *syntax_table = XCHAR_TABLE (buf->mirror_syntax_table);
 
   CHECK_STRING (string);
   len = XSTRING_CHAR_LENGTH (string);
@@ -1845,7 +1848,7 @@ and you do not need to specify it.)
   Emchar c, prevc;
   Charcount inslen;
   struct buffer *buf;
-  struct Lisp_Char_Table *syntax_table;
+  Lisp_Char_Table *syntax_table;
   int mc_count;
   Lisp_Object buffer;
   int_dynarr *ul_action_dynarr = 0;
@@ -2545,8 +2548,8 @@ void
 syms_of_search (void)
 {
 
-  deferror (&Qsearch_failed, "search-failed", "Search failed", Qerror);
-  deferror (&Qinvalid_regexp, "invalid-regexp", "Invalid regexp", Qerror);
+  DEFERROR_STANDARD (Qsearch_failed, Qinvalid_operation);
+  DEFERROR_STANDARD (Qinvalid_regexp, Qsyntax_error);
 
   DEFSUBR (Flooking_at);
   DEFSUBR (Fposix_looking_at);
@@ -2574,9 +2577,12 @@ syms_of_search (void)
 }
 
 void
-vars_of_search (void)
+reinit_vars_of_search (void)
 {
-  REGISTER int i;
+  int i;
+
+  last_thing_searched = Qnil;
+  staticpro_nodump (&last_thing_searched);
 
   for (i = 0; i < REGEXP_CACHE_SIZE; ++i)
     {
@@ -2584,13 +2590,16 @@ vars_of_search (void)
       searchbufs[i].buf.buffer = (unsigned char *) xmalloc (100);
       searchbufs[i].buf.fastmap = searchbufs[i].fastmap;
       searchbufs[i].regexp = Qnil;
-      staticpro (&searchbufs[i].regexp);
+      staticpro_nodump (&searchbufs[i].regexp);
       searchbufs[i].next = (i == REGEXP_CACHE_SIZE-1 ? 0 : &searchbufs[i+1]);
     }
   searchbuf_head = &searchbufs[0];
+}
 
-  last_thing_searched = Qnil;
-  staticpro (&last_thing_searched);
+void
+vars_of_search (void)
+{
+  reinit_vars_of_search ();
 
   DEFVAR_LISP ("forward-word-regexp", &Vforward_word_regexp /*
 *Regular expression to be used in `forward-word'.