update.
[chise/xemacs-chise.git-] / src / insdel.c
index b3e4574..90efb77 100644 (file)
@@ -219,7 +219,9 @@ Boston, MA 02111-1307, USA.  */
 #define MAX_BUFPOS_GAP_SIZE_3 (65535/3)
 #define MAX_BYTIND_GAP_SIZE_3 (3 * MAX_BUFPOS_GAP_SIZE_3)
 
+#ifndef UTF2000
 short three_to_one_table[1 + MAX_BYTIND_GAP_SIZE_3];
+#endif
 
 /* Various macros modelled along the lines of those in buffer.h.
    Purposefully omitted from buffer.h because files other than this
@@ -431,7 +433,11 @@ bufpos_to_bytind_func (struct buffer *buf, Bufpos x)
   bufmax = buf->text->mule_bufmax;
   bytmin = buf->text->mule_bytmin;
   bytmax = buf->text->mule_bytmax;
+#ifdef UTF2000
+  size = buf->text->mule_size;
+#else
   size = (1 << buf->text->mule_shifter) + !!buf->text->mule_three_p;
+#endif
 
   /* The basic idea here is that we shift the "known region" up or down
      until it overlaps the specified position.  We do this by moving
@@ -626,11 +632,16 @@ bufpos_to_bytind_func (struct buffer *buf, Bufpos x)
      discovered isn't too large, because we use a fixed-length
      table to divide by 3. */
 
+#ifdef UTF2000
+  buf->text->mule_size = size;
+#endif
   if (size == 3)
     {
       int gap = bytmax - bytmin;
+#ifndef UTF2000
       buf->text->mule_three_p = 1;
       buf->text->mule_shifter = 1;
+#endif
 
       if (gap > MAX_BYTIND_GAP_SIZE_3)
        {
@@ -648,11 +659,13 @@ bufpos_to_bytind_func (struct buffer *buf, Bufpos x)
     }
   else
     {
+#ifndef UTF2000
       buf->text->mule_three_p = 0;
       if (size == 4)
        buf->text->mule_shifter = 2;
       else
        buf->text->mule_shifter = size - 1;
+#endif
     }
 
   buf->text->mule_bufmin = bufmin;
@@ -708,7 +721,11 @@ bytind_to_bufpos_func (struct buffer *buf, Bytind x)
   bufmax = buf->text->mule_bufmax;
   bytmin = buf->text->mule_bytmin;
   bytmax = buf->text->mule_bytmax;
+#ifdef UTF2000
+  size = buf->text->mule_size;
+#else
   size = (1 << buf->text->mule_shifter) + !!buf->text->mule_three_p;
+#endif
 
   /* The basic idea here is that we shift the "known region" up or down
      until it overlaps the specified position.  We do this by moving
@@ -903,11 +920,16 @@ bytind_to_bufpos_func (struct buffer *buf, Bytind x)
      discovered isn't too large, because we use a fixed-length
      table to divide by 3. */
 
+#ifdef UTF2000
+  buf->text->mule_size = size;
+  #endif
   if (size == 3)
     {
       int gap = bytmax - bytmin;
+#ifndef UTF2000
       buf->text->mule_three_p = 1;
       buf->text->mule_shifter = 1;
+#endif
 
       if (gap > MAX_BYTIND_GAP_SIZE_3)
        {
@@ -925,11 +947,13 @@ bytind_to_bufpos_func (struct buffer *buf, Bytind x)
     }
   else
     {
+#ifndef UTF2000
       buf->text->mule_three_p = 0;
       if (size == 4)
        buf->text->mule_shifter = 2;
       else
        buf->text->mule_shifter = size - 1;
+#endif
     }
 
   buf->text->mule_bufmin = bufmin;
@@ -965,7 +989,11 @@ buffer_mule_signal_inserted_region (struct buffer *buf, Bufpos start,
                                    Bytecount bytelength,
                                    Charcount charlength)
 {
+#ifdef UTF2000
+  int size = buf->text->mule_size;
+#else
   int size = (1 << buf->text->mule_shifter) + !!buf->text->mule_three_p;
+#endif
   int i;
 
   /* Adjust the cache of known positions. */
@@ -1605,7 +1633,7 @@ static void
 adjust_markers (struct buffer *buf, Memind from, Memind to,
                Bytecount amount)
 {
-  struct Lisp_Marker *m;
+  Lisp_Marker *m;
 
   for (m = BUF_MARKERS (buf); m; m = marker_next (m))
     m->memind = do_marker_adjustment (m->memind, from, to, amount);
@@ -1617,7 +1645,7 @@ adjust_markers (struct buffer *buf, Memind from, Memind to,
 static void
 adjust_markers_for_insert (struct buffer *buf, Memind ind, Bytecount amount)
 {
-  struct Lisp_Marker *m;
+  Lisp_Marker *m;
 
   for (m = BUF_MARKERS (buf); m; m = marker_next (m))
     {
@@ -1631,18 +1659,6 @@ adjust_markers_for_insert (struct buffer *buf, Memind ind, Bytecount amount)
 /*                  Routines for dealing with the gap                   */
 /************************************************************************/
 
-/* XEmacs requires an ANSI C compiler, and it damn well better have a
-   working memmove() */
-#define GAP_USE_BCOPY
-#ifdef BCOPY_UPWARD_SAFE
-# undef BCOPY_UPWARD_SAFE
-#endif
-#ifdef BCOPY_DOWNWARD_SAFE
-# undef BCOPY_DOWNWARD_SAFE
-#endif
-#define BCOPY_UPWARD_SAFE 1
-#define BCOPY_DOWNWARD_SAFE 1
-
 /* maximum amount of memory moved in a single chunk.  Increasing this
    value improves gap-motion efficiency but decreases QUIT responsiveness
    time.  Was 32000 but today's processors are faster and files are
@@ -1683,23 +1699,15 @@ gap_left (struct buffer *buf, Bytind pos)
       /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */
       if (i > GAP_MOVE_CHUNK)
        i = GAP_MOVE_CHUNK;
-#ifdef GAP_USE_BCOPY
-      if (i >= 128
-         /* bcopy is safe if the two areas of memory do not overlap
-            or on systems where bcopy is always safe for moving upward.  */
-         && (BCOPY_UPWARD_SAFE
-             || to - from >= 128))
+
+      if (i >= 128)
        {
-         /* If overlap is not safe, avoid it by not moving too many
-            characters at once.  */
-         if (!BCOPY_UPWARD_SAFE && i > to - from)
-           i = to - from;
          new_s1 -= i;
-         from -= i, to -= i;
+         from   -= i;
+         to     -= i;
          memmove (to, from, i);
        }
       else
-#endif
        {
          new_s1 -= i;
          while (--i >= 0)
@@ -1762,23 +1770,15 @@ gap_right (struct buffer *buf, Bytind pos)
       /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */
       if (i > GAP_MOVE_CHUNK)
        i = GAP_MOVE_CHUNK;
-#ifdef GAP_USE_BCOPY
-      if (i >= 128
-         /* bcopy is safe if the two areas of memory do not overlap
-            or on systems where bcopy is always safe for moving downward. */
-         && (BCOPY_DOWNWARD_SAFE
-             || from - to >= 128))
+
+      if (i >= 128)
        {
-         /* If overlap is not safe, avoid it by not moving too many
-            characters at once.  */
-         if (!BCOPY_DOWNWARD_SAFE && i > from - to)
-           i = from - to;
          new_s1 += i;
          memmove (to, from, i);
-         from += i, to += i;
+         from += i;
+         to   += i;
        }
       else
-#endif
        {
          new_s1 += i;
          while (--i >= 0)
@@ -3101,7 +3101,7 @@ barf_if_buffer_read_only (struct buffer *buf, Bufpos from, Bufpos to)
 }
 
 void
-find_charsets_in_bufbyte_string (unsigned char *charsets, CONST Bufbyte *str,
+find_charsets_in_bufbyte_string (Charset_ID *charsets, CONST Bufbyte *str,
                                 Bytecount len)
 {
 #ifndef MULE
@@ -3109,18 +3109,25 @@ find_charsets_in_bufbyte_string (unsigned char *charsets, CONST Bufbyte *str,
   charsets[0] = 1;
 #else
   CONST Bufbyte *strend = str + len;
-  memset (charsets, 0, NUM_LEADING_BYTES);
+  memset (charsets, 0, NUM_LEADING_BYTES * sizeof(Charset_ID));
 
   while (str < strend)
     {
-      charsets[CHAR_LEADING_BYTE (charptr_emchar (str)) - 128] = 1;
+#ifdef UTF2000
+      charsets[CHAR_CHARSET_ID (charptr_emchar (str))
+             - MIN_LEADING_BYTE] = 1;
+#else /* I'm not sure the definition for UTF2000 works with leading-byte
+        representation. */
+      charsets[CHAR_LEADING_BYTE (charptr_emchar (str))
+             - MIN_LEADING_BYTE] = 1;
+#endif
       INC_CHARPTR (str);
     }
 #endif
 }
 
 void
-find_charsets_in_emchar_string (unsigned char *charsets, CONST Emchar *str,
+find_charsets_in_emchar_string (Charset_ID *charsets, CONST Emchar *str,
                                Charcount len)
 {
 #ifndef MULE
@@ -3129,10 +3136,15 @@ find_charsets_in_emchar_string (unsigned char *charsets, CONST Emchar *str,
 #else
   int i;
 
-  memset (charsets, 0, NUM_LEADING_BYTES);
+  memset (charsets, 0, NUM_LEADING_BYTES * sizeof(Charset_ID));
   for (i = 0; i < len; i++)
     {
-      charsets[CHAR_LEADING_BYTE (str[i]) - 128] = 1;
+#ifdef UTF2000
+      charsets[CHAR_CHARSET_ID (str[i]) - MIN_LEADING_BYTE] = 1;
+#else /* I'm not sure the definition for UTF2000 works with leading-byte
+        representation. */
+      charsets[CHAR_LEADING_BYTE (str[i]) - MIN_LEADING_BYTE] = 1;
+#endif
     }
 #endif
 }
@@ -3147,7 +3159,7 @@ bufbyte_string_displayed_columns (CONST Bufbyte *str, Bytecount len)
     {
 #ifdef MULE
       Emchar ch = charptr_emchar (str);
-      cols += XCHARSET_COLUMNS (CHAR_CHARSET (ch));
+      cols += CHAR_COLUMNS (ch);
 #else
       cols++;
 #endif
@@ -3165,7 +3177,7 @@ emchar_string_displayed_columns (CONST Emchar *str, Charcount len)
   int i;
 
   for (i = 0; i < len; i++)
-    cols += XCHARSET_COLUMNS (CHAR_CHARSET (str[i]));
+    cols += CHAR_COLUMNS (str[i]);
 
   return cols;
 #else  /* not MULE */
@@ -3258,13 +3270,17 @@ convert_emchar_string_into_malloced_string (Emchar *arr, int nels,
 void
 reinit_vars_of_insdel (void)
 {
+#ifndef UTF2000
   int i;
+#endif
 
   inside_change_hook = 0;
   in_first_change = 0;
 
+#ifndef UTF2000
   for (i = 0; i <= MAX_BYTIND_GAP_SIZE_3; i++)
     three_to_one_table[i] = i / 3;
+#endif
 }
 
 void
@@ -3294,8 +3310,12 @@ init_buffer_text (struct buffer *b)
 
        b->text->mule_bufmin = b->text->mule_bufmax = 1;
        b->text->mule_bytmin = b->text->mule_bytmax = 1;
+#ifdef UTF2000
+       b->text->mule_size = 0;
+#else
        b->text->mule_shifter = 0;
        b->text->mule_three_p = 0;
+#endif
 
        for (i = 0; i < 16; i++)
          {