Partially sync files.el from XEmacs 21.5 for wildcard support.
[sxemacs] / src / search.c
index 72206aa..1a5f0a1 100644 (file)
@@ -46,9 +46,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>. */
  (!NILP (table) ? TRT_TABLE_OF (table, (Emchar) pos) : pos)
 \f
 #include "elhash.h"
+/* Make sure these are ALWAYS powers of 2 */
 #define REGEXP_CACHE_SIZE 0x80
 #define REGEXP_CACHE_HASH_MASK (REGEXP_CACHE_SIZE-1)
 #define REGEXP_FASTMAP_SIZE 0400
+#define REGEXP_FASTMAP_MASK (REGEXP_FASTMAP_SIZE-1)
 
 #define __REGEXP_DEBUG__(args...)      fprintf(stderr, "REGEXP " args)
 #ifndef REGEXP_DEBUG_FLAG
@@ -333,12 +335,8 @@ compile_pattern(Lisp_Object pattern,
 static void
 compre_prfun(Lisp_Object obj, Lisp_Object pcfun, int escflag)
 {
-       char buf[18];
-       write_c_string("#<compiled regexp ", pcfun);
-       snprintf(buf, 17, "%lx>",
-                (long unsigned int)((COMPRE_GET(obj))->buffer));
-       write_c_string(buf, pcfun);
-
+       write_fmt_str(pcfun, "#<compiled regexp %lx",
+                     (long unsigned int)((COMPRE_GET(obj))->buffer));
        if (escflag);
 }
 
@@ -750,6 +748,8 @@ fast_string_match(Lisp_Object regexp, const Bufbyte * nonreloc,
 
        fixup_internal_substring(nonreloc, reloc, offset, &length);
 
+
+
        if (!NILP(reloc)) {
                if (no_quit) {
                        newnonreloc = XSTRING_DATA(reloc);
@@ -759,6 +759,13 @@ fast_string_match(Lisp_Object regexp, const Bufbyte * nonreloc,
                           serious rewriting of re_search(). */
                        /* yeah, let's rewrite this bugger, the warning
                           hereafter is inevitable too */
+                       if ( length < 0)
+                               /* By this point
+                                  fixup_internal_substring should
+                                  have updated length, if it didn't
+                                  return with failure...
+                               */
+                               return -1;
                        newnonreloc = alloca(length);
                        memcpy((void*)newnonreloc, (void*)XSTRING_DATA(reloc), length);
                }
@@ -1862,9 +1869,9 @@ boyer_moore(struct buffer *buf, Bufbyte * base_pat, Bytecount len,
                                this_translated = 0;
                        }
                        if (ch > REGEXP_FASTMAP_SIZE)
-                               j = ((unsigned char)ch | 0200);
+                               j = ((unsigned char)(ch & REGEXP_FASTMAP_MASK)| 0200);
                        else
-                               j = (unsigned char)ch;
+                               j = (unsigned char)(ch & REGEXP_FASTMAP_MASK);
 
                        if (i == infinity)
                                stride_for_teases = BM_tab[j];
@@ -1877,9 +1884,9 @@ boyer_moore(struct buffer *buf, Bufbyte * base_pat, Bytecount len,
                                while (1) {
                                        ch = TRANSLATE(inverse_trt, ch);
                                        if (ch > REGEXP_FASTMAP_SIZE)
-                                               j = ((unsigned char)ch | 0200);
+                                               j = ((unsigned char)(ch & REGEXP_FASTMAP_MASK) | 0200);
                                        else
-                                               j = (unsigned char)ch;
+                                               j = (unsigned char)(ch & REGEXP_FASTMAP_MASK);
 
                                        /* For all the characters that map into CH,
                                           set up simple_translate to map the last byte