]> code.delx.au - gnu-emacs/blobdiff - src/search.c
Put doc strings in comments.
[gnu-emacs] / src / search.c
index 48528bea12123f0642872ab64f4f745195dfaa40..f05f2cc0bf327a321a93b7e5c7150b1314101867 100644 (file)
@@ -33,9 +33,6 @@ Boston, MA 02111-1307, USA.  */
 #include <sys/types.h>
 #include "regex.h"
 
-#define min(a, b) ((a) < (b) ? (a) : (b))
-#define max(a, b) ((a) > (b) ? (a) : (b))
-
 #define REGEXP_CACHE_SIZE 20
 
 /* If the regexp is non-nil, then the buffer contains the compiled form
@@ -180,7 +177,7 @@ compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte)
 void
 shrink_regexp_cache ()
 {
-  struct regexp_cache *cp, **cpp;
+  struct regexp_cache *cp;
 
   for (cp = searchbuf_head; cp != 0; cp = cp->next)
     {
@@ -949,7 +946,6 @@ trivial_regexp_p (regexp)
 {
   int len = STRING_BYTES (XSTRING (regexp));
   unsigned char *s = XSTRING (regexp)->data;
-  unsigned char c;
   while (--len >= 0)
     {
       switch (*s++)
@@ -963,7 +959,7 @@ trivial_regexp_p (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 '}':
            case 'c': case 'C': /* for categoryspec and notcategoryspec */
            case '1': case '2': case '3': case '4': case '5':
            case '6': case '7': case '8': case '9':
@@ -1031,7 +1027,7 @@ search_buffer (string, pos, pos_byte, lim, lim_byte, n,
   /* Null string is found at starting position.  */
   if (len == 0 || n == 0)
     {
-      set_search_regs (pos, 0);
+      set_search_regs (pos_byte, 0);
       return pos;
     }
 
@@ -1527,7 +1523,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt,
 {
   int direction = ((n > 0) ? 1 : -1);
   register int dirlen;
-  int infinity, limit, k, stride_for_teases = 0;
+  int infinity, limit, stride_for_teases = 0;
   register int *BM_tab;
   int *BM_tab_base;
   register unsigned char *cursor, *p_limit;  
@@ -1975,7 +1971,7 @@ wordify (string)
   if (SYNTAX (prev_c) == Sword)
     word_count++;
   if (!word_count)
-    return build_string ("");
+    return empty_string;
 
   adjust = - punct_count + 5 * (word_count - 1) + 4;
   if (STRING_MULTIBYTE (string))
@@ -2030,6 +2026,10 @@ The match found must not extend before that position.\n\
 Optional third argument, if t, means if fail just return nil (no error).\n\
  If not nil and not t, position at limit of search and return nil.\n\
 Optional fourth argument is repeat count--search for successive occurrences.\n\
+\n\
+Search case-sensitivity is determined by the value of the variable\n\
+`case-fold-search', which see.\n\
+\n\
 See also the functions `match-beginning', `match-end' and `replace-match'.")
   (string, bound, noerror, count)
      Lisp_Object string, bound, noerror, count;
@@ -2046,6 +2046,10 @@ The match found must not extend after that position.  nil is equivalent\n\
 Optional third argument, if t, means if fail just return nil (no error).\n\
   If not nil and not t, move to limit of search and return nil.\n\
 Optional fourth argument is repeat count--search for successive occurrences.\n\
+\n\
+Search case-sensitivity is determined by the value of the variable\n\
+`case-fold-search', which see.\n\
+\n\
 See also the functions `match-beginning', `match-end' and `replace-match'.")
   (string, bound, noerror, count)
      Lisp_Object string, bound, noerror, count;
@@ -2176,12 +2180,18 @@ FIXEDCASE and LITERAL are optional arguments.\n\
 Leaves point at end of replacement text.\n\
 \n\
 The optional fourth argument STRING can be a string to modify.\n\
-In that case, this function creates and returns a new string\n\
-which is made by replacing the part of STRING that was matched.\n\
+This is meaningful when the previous match was done against STRING,\n\
+using `string-match'.  When used this way, `replace-match'\n\
+creates and returns a new string made by copying STRING and replacing\n\
+the part of STRING that was matched.\n\
 \n\
-The optional fifth argument SUBEXP specifies a subexpression of the match.\n\
-It says to replace just that subexpression instead of the whole match.\n\
-This is useful only after a regular expression search or match\n\
+The optional fifth argument SUBEXP specifies a subexpression;\n\
+it says to replace just that subexpression with NEWTEXT,\n\
+rather than replacing the entire matched text.\n\
+This is, in a vague sense, the inverse of using `\\N' in NEWTEXT;\n\
+`\\N' copies subexp N into NEWTEXT, but using N as SUBEXP puts\n\
+NEWTEXT in place of subexp N.\n\
+This is useful only after a regular expression search or match,\n\
 since only regular expressions have distinguished subexpressions.")
   (newtext, fixedcase, literal, string, subexp)
      Lisp_Object newtext, fixedcase, literal, string, subexp;
@@ -2410,7 +2420,7 @@ since only regular expressions have distinguished subexpressions.")
       return concat3 (before, newtext, after);
     }
 
-  /* Record point, the move (quietly) to the start of the match.  */
+  /* Record point, then move (quietly) to the start of the match.  */
   if (PT >= search_regs.end[sub])
     opoint = PT - ZV;
   else if (PT > search_regs.start[sub])
@@ -2738,6 +2748,9 @@ LIST should have been created by calling `match-data' previously.")
                                       length * sizeof (regoff_t));
          }
 
+       for (i = search_regs.num_regs; i < length; i++)
+         search_regs.start[i] = -1;
+
        search_regs.num_regs = length;
       }
   }
@@ -2752,6 +2765,8 @@ LIST should have been created by calling `match-data' previously.")
        }
       else
        {
+         int from;
+
          if (MARKERP (marker))
            {
              if (XMARKER (marker)->buffer == 0)
@@ -2761,7 +2776,7 @@ LIST should have been created by calling `match-data' previously.")
            }
 
          CHECK_NUMBER_COERCE_MARKER (marker, 0);
-         search_regs.start[i] = XINT (marker);
+         from = XINT (marker);
          list = Fcdr (list);
 
          marker = Fcar (list);
@@ -2769,6 +2784,7 @@ LIST should have been created by calling `match-data' previously.")
            XSETFASTINT (marker, 0);
 
          CHECK_NUMBER_COERCE_MARKER (marker, 0);
+         search_regs.start[i] = from;
          search_regs.end[i] = XINT (marker);
        }
       list = Fcdr (list);