Delete document about Emchar accessors.
[chise/xemacs-chise.git] / src / buffer.h
index f9bf6c1..6ca50c7 100644 (file)
@@ -32,8 +32,10 @@ Boston, MA 02111-1307, USA.  */
 #ifndef _XEMACS_BUFFER_H_
 #define _XEMACS_BUFFER_H_
 
-#ifdef MULE
-#include "mule-charset.h"
+#include "character.h"
+
+#ifdef UTF2000
+#include "mb-utf-8.h"
 #endif
 
 /************************************************************************/
@@ -94,7 +96,11 @@ struct buffer_text
      This information is text-only so it goes here. */
   Bufpos mule_bufmin, mule_bufmax;
   Bytind mule_bytmin, mule_bytmax;
+#ifdef UTF2000
+  int mule_size;
+#else
   int mule_shifter, mule_three_p;
+#endif
 
   /* And we also cache 16 positions for fairly fast access near those
      positions. */
@@ -339,6 +345,9 @@ for (mps_bufcons = Qunbound,                                                        \
        Return a pointer to the beginning of the character offset N
        (in characters) from PTR.
 
+   MAX_EMCHAR_LEN:
+       Maximum number of buffer bytes per Emacs character.
+
 
    (C) For retrieving or changing the character pointed to by a charptr:
    ---------------------------------------------------------------------
@@ -358,28 +367,6 @@ for (mps_bufcons = Qunbound,                                                       \
        Retrieve the character pointed to by PTR and store it as
        internally-formatted text in PTR2.
 
-
-   (D) For working with Emchars:
-   -----------------------------
-
-   [Note that there are other functions/macros for working with Emchars
-    in mule-charset.h, for retrieving the charset of an Emchar
-    and such.  These are only valid when MULE is defined.]
-
-   valid_char_p (ch):
-       Return whether the given Emchar is valid.
-
-   CHARP (ch):
-       Return whether the given Lisp_Object is a character.
-
-   CHECK_CHAR_COERCE_INT (ch):
-       Signal an error if CH is not a valid character or integer Lisp_Object.
-       If CH is an integer Lisp_Object, convert it to a character Lisp_Object,
-       but merely by repackaging, without performing tests for char validity.
-
-   MAX_EMCHAR_LEN:
-       Maximum number of buffer bytes per Emacs character.
-
 */
 
 
@@ -409,6 +396,9 @@ for (mps_bufcons = Qunbound,                                                        \
 #define REAL_INC_CHARPTR(ptr) \
   ((void) ((ptr) += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr))))
 
+#define REAL_INC_CHARBYTIND(ptr,pos) \
+  (pos += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr)))
+
 #define REAL_DEC_CHARPTR(ptr) do {     \
   (ptr)--;                             \
 } while (!VALID_CHARPTR_P (ptr))
@@ -419,6 +409,11 @@ for (mps_bufcons = Qunbound,                                                       \
   REAL_INC_CHARPTR (ptr);              \
 } while (0)
 
+#define INC_CHARBYTIND(ptr,pos) do {           \
+  ASSERT_VALID_CHARPTR (ptr);          \
+  REAL_INC_CHARBYTIND (ptr,pos);               \
+} while (0)
+
 #define DEC_CHARPTR(ptr) do {                  \
   CONST Bufbyte *dc_ptr1 = (ptr);              \
   CONST Bufbyte *dc_ptr2 = dc_ptr1;            \
@@ -429,6 +424,7 @@ for (mps_bufcons = Qunbound,                                                        \
 } while (0)
 
 #else /* ! ERROR_CHECK_BUFPOS */
+#define INC_CHARBYTIND(ptr,pos) REAL_INC_CHARBYTIND (ptr,pos)
 #define INC_CHARPTR(ptr) REAL_INC_CHARPTR (ptr)
 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr)
 #endif /* ! ERROR_CHECK_BUFPOS */
@@ -469,6 +465,16 @@ charptr_n_addr (CONST Bufbyte *ptr, Charcount offset)
   return ptr + charcount_to_bytecount (ptr, offset);
 }
 
+#ifdef UTF2000
+# define MAX_EMCHAR_LEN 6
+#else
+#ifdef MULE
+# define MAX_EMCHAR_LEN 4
+#else
+# define MAX_EMCHAR_LEN 1
+#endif
+#endif
+
 /* -------------------------------------------------------------------- */
 /* (C) For retrieving or changing the character pointed to by a charptr */
 /* -------------------------------------------------------------------- */
@@ -521,63 +527,6 @@ charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2)
 #define charptr_emchar_n(ptr, offset) \
   charptr_emchar (charptr_n_addr (ptr, offset))
 
-
-/* ---------------------------- */
-/* (D) For working with Emchars */
-/* ---------------------------- */
-
-#ifdef MULE
-
-int non_ascii_valid_char_p (Emchar ch);
-
-INLINE int valid_char_p (Emchar ch);
-INLINE int
-valid_char_p (Emchar ch)
-{
-  return ((unsigned int) (ch) <= 0xff) || non_ascii_valid_char_p (ch);
-}
-
-#else /* not MULE */
-
-#define valid_char_p(ch) ((unsigned int) (ch) <= 0xff)
-
-#endif /* not MULE */
-
-#define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x)))
-
-#define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x))
-
-#ifdef ERROR_CHECK_TYPECHECK
-
-INLINE Emchar XCHAR_OR_CHAR_INT (Lisp_Object obj);
-INLINE Emchar
-XCHAR_OR_CHAR_INT (Lisp_Object obj)
-{
-  assert (CHAR_OR_CHAR_INTP (obj));
-  return CHARP (obj) ? XCHAR (obj) : XINT (obj);
-}
-
-#else
-
-#define XCHAR_OR_CHAR_INT(obj) (CHARP ((obj)) ? XCHAR ((obj)) : XINT ((obj)))
-
-#endif
-
-#define CHECK_CHAR_COERCE_INT(x) do {          \
-  if (CHARP (x))                               \
-     ;                                         \
-  else if (CHAR_INTP (x))                      \
-    x = make_char (XINT (x));                  \
-  else                                         \
-    x = wrong_type_argument (Qcharacterp, x);  \
-} while (0)
-
-#ifdef MULE
-# define MAX_EMCHAR_LEN 4
-#else
-# define MAX_EMCHAR_LEN 1
-#endif
-
 \f
 /*----------------------------------------------------------------------*/
 /*         Accessor macros for important positions in a buffer         */
@@ -963,7 +912,9 @@ Bufpos bytind_to_bufpos_func (struct buffer *buf, Bytind x);
    64K for width-three characters.
    */
 
+#ifndef UTF2000
 extern short three_to_one_table[];
+#endif
 
 INLINE int real_bufpos_to_bytind (struct buffer *buf, Bufpos x);
 INLINE int
@@ -971,8 +922,13 @@ real_bufpos_to_bytind (struct buffer *buf, Bufpos x)
 {
   if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax)
     return (buf->text->mule_bytmin +
+#ifdef UTF2000
+           (x - buf->text->mule_bufmin) * buf->text->mule_size
+#else
            ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) +
-           (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : 0));
+           (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : 0)
+#endif
+           );
   else
     return bufpos_to_bytind_func (buf, x);
 }
@@ -983,9 +939,15 @@ real_bytind_to_bufpos (struct buffer *buf, Bytind x)
 {
   if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax)
     return (buf->text->mule_bufmin +
+#ifdef UTF2000
+           (buf->text->mule_size == 0 ? 0 :
+            (x - buf->text->mule_bytmin) / buf->text->mule_size)
+#else
            ((buf->text->mule_three_p
              ? three_to_one_table[x - buf->text->mule_bytmin]
-             : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter)));
+             : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter))
+#endif
+           );
   else
     return bytind_to_bufpos_func (buf, x);
 }
@@ -1341,6 +1303,8 @@ Bufbyte *convert_from_external_format (CONST Extbyte *ptr,
 
 #ifndef MULE
 
+typedef int Charset_ID;
+
 #define Vcharset_ascii Qnil
 
 #define CHAR_CHARSET(ch) Vcharset_ascii
@@ -1513,6 +1477,7 @@ extern struct buffer *current_buffer;
 
 /* This is the initial (startup) directory, as used for the *scratch* buffer.
    We're making this a global to make others aware of the startup directory.
+   `initial_directory' is stored in external format.
  */
 extern char initial_directory[];
 extern void init_initial_directory (void);   /* initialize initial_directory */
@@ -1592,10 +1557,10 @@ int beginning_of_line_p (struct buffer *b, Bufpos pt);
 
 /* from insdel.c */
 void set_buffer_point (struct buffer *buf, Bufpos pos, Bytind bipos);
-void find_charsets_in_bufbyte_string (unsigned char *charsets,
+void find_charsets_in_bufbyte_string (Charset_ID *charsets,
                                      CONST Bufbyte *str,
                                      Bytecount len);
-void find_charsets_in_emchar_string (unsigned char *charsets,
+void find_charsets_in_emchar_string (Charset_ID *charsets,
                                     CONST Emchar *str,
                                     Charcount len);
 int bufbyte_string_displayed_columns (CONST Bufbyte *str, Bytecount len);