Merge r21-4-11-chise-0_20-=ucs.
[chise/xemacs-chise.git.1] / src / chartab.h
index ac23e00..8fa102b 100644 (file)
@@ -1,6 +1,7 @@
 /* Declarations having to do with Mule char tables.
    Copyright (C) 1992 Free Software Foundation, Inc.
    Copyright (C) 1995 Sun Microsystems, Inc.
+   Copyright (C) 1999,2000,2001,2002 MORIOKA Tomohiko
 
 This file is part of XEmacs.
 
@@ -24,8 +25,92 @@ Boston, MA 02111-1307, USA.  */
    This file was written independently of the FSF implementation,
    and is not compatible. */
 
-#ifndef _MULE_CHARTAB_H
-#define _MULE_CHARTAB_H
+#ifndef INCLUDED_chartab_h_
+#define INCLUDED_chartab_h_
+
+
+#ifdef UTF2000
+
+#ifdef HAVE_CHISE_CLIENT
+#include "database.h"
+#endif
+
+EXFUN (Fmake_char, 3);
+EXFUN (Fdecode_char, 3);
+
+EXFUN (Fput_char_attribute, 3);
+
+EXFUN (Ffind_char, 1);
+
+extern Lisp_Object Qdowncase, Qflippedcase, Q_lowercase, Q_uppercase;
+
+
+/************************************************************************/
+/*                         Char-ID Tables                              */
+/************************************************************************/
+
+struct Lisp_Uint8_Byte_Table
+{
+  struct lcrecord_header header;
+
+  unsigned char property[256];
+};
+typedef struct Lisp_Uint8_Byte_Table Lisp_Uint8_Byte_Table;
+
+DECLARE_LRECORD (uint8_byte_table, Lisp_Uint8_Byte_Table);
+#define XUINT8_BYTE_TABLE(x) \
+   XRECORD (x, uint8_byte_table, Lisp_Uint8_Byte_Table)
+#define XSETUINT8_BYTE_TABLE(x, p) XSETRECORD (x, p, uint8_byte_table)
+#define UINT8_BYTE_TABLE_P(x) RECORDP (x, uint8_byte_table)
+#define GC_UINT8_BYTE_TABLE_P(x) GC_RECORDP (x, uint8_byte_table)
+/* #define CHECK_UINT8_BYTE_TABLE(x) CHECK_RECORD (x, uint8_byte_table)
+   char table entries should never escape to Lisp */
+
+
+struct Lisp_Uint16_Byte_Table
+{
+  struct lcrecord_header header;
+
+  unsigned short property[256];
+};
+typedef struct Lisp_Uint16_Byte_Table Lisp_Uint16_Byte_Table;
+
+DECLARE_LRECORD (uint16_byte_table, Lisp_Uint16_Byte_Table);
+#define XUINT16_BYTE_TABLE(x) \
+   XRECORD (x, uint16_byte_table, Lisp_Uint16_Byte_Table)
+#define XSETUINT16_BYTE_TABLE(x, p) XSETRECORD (x, p, uint16_byte_table)
+#define UINT16_BYTE_TABLE_P(x) RECORDP (x, uint16_byte_table)
+#define GC_UINT16_BYTE_TABLE_P(x) GC_RECORDP (x, uint16_byte_table)
+/* #define CHECK_UINT16_BYTE_TABLE(x) CHECK_RECORD (x, uint16_byte_table)
+   char table entries should never escape to Lisp */
+
+
+struct Lisp_Byte_Table
+{
+  struct lcrecord_header header;
+
+  Lisp_Object property[256];
+};
+typedef struct Lisp_Byte_Table Lisp_Byte_Table;
+
+DECLARE_LRECORD (byte_table, Lisp_Byte_Table);
+#define XBYTE_TABLE(x) XRECORD (x, byte_table, Lisp_Byte_Table)
+#define XSETBYTE_TABLE(x, p) XSETRECORD (x, p, byte_table)
+#define BYTE_TABLE_P(x) RECORDP (x, byte_table)
+#define GC_BYTE_TABLE_P(x) GC_RECORDP (x, byte_table)
+/* #define CHECK_BYTE_TABLE(x) CHECK_RECORD (x, byte_table)
+   char table entries should never escape to Lisp */
+
+Lisp_Object get_byte_table (Lisp_Object table, unsigned char idx);
+
+Lisp_Object put_byte_table (Lisp_Object table, unsigned char idx,
+                           Lisp_Object value);
+
+
+Lisp_Object make_char_id_table (Lisp_Object initval);
+
+#endif
+
 
 /************************************************************************/
 /*                               Char Tables                            */
@@ -35,16 +120,7 @@ Boston, MA 02111-1307, USA.  */
    When not under Mule, there are only 256 possible characters
    so we just represent them directly. */
 
-#ifdef MULE
-
-DECLARE_LRECORD (char_table_entry, struct Lisp_Char_Table_Entry);
-#define XCHAR_TABLE_ENTRY(x) \
-  XRECORD (x, char_table_entry, struct Lisp_Char_Table_Entry)
-#define XSETCHAR_TABLE_ENTRY(x, p) XSETRECORD (x, p, char_table_entry)
-#define CHAR_TABLE_ENTRYP(x) RECORDP (x, char_table_entry)
-#define GC_CHAR_TABLE_ENTRYP(x) GC_RECORDP (x, char_table_entry)
-/* #define CHECK_CHAR_TABLE_ENTRY(x) CHECK_RECORD (x, char_table_entry)
-   char table entries should never escape to Lisp */
+#if defined(MULE)&&!defined(UTF2000)
 
 struct Lisp_Char_Table_Entry
 {
@@ -55,20 +131,17 @@ struct Lisp_Char_Table_Entry
      variable-size and add an offset value into this structure. */
   Lisp_Object level2[96];
 };
+typedef struct Lisp_Char_Table_Entry Lisp_Char_Table_Entry;
 
-#endif /* MULE */
-
-DECLARE_LRECORD (char_table, struct Lisp_Char_Table);
-#define XCHAR_TABLE(x) \
-  XRECORD (x, char_table, struct Lisp_Char_Table)
-#define XSETCHAR_TABLE(x, p) XSETRECORD (x, p, char_table)
-#define CHAR_TABLEP(x) RECORDP (x, char_table)
-#define GC_CHAR_TABLEP(x) GC_RECORDP (x, char_table)
-#define CHECK_CHAR_TABLE(x) CHECK_RECORD (x, char_table)
-#define CONCHECK_CHAR_TABLE(x) CONCHECK_RECORD (x, char_table)
+DECLARE_LRECORD (char_table_entry, Lisp_Char_Table_Entry);
+#define XCHAR_TABLE_ENTRY(x) \
+  XRECORD (x, char_table_entry, Lisp_Char_Table_Entry)
+#define XSETCHAR_TABLE_ENTRY(x, p) XSETRECORD (x, p, char_table_entry)
+#define CHAR_TABLE_ENTRYP(x) RECORDP (x, char_table_entry)
+/* #define CHECK_CHAR_TABLE_ENTRY(x) CHECK_RECORD (x, char_table_entry)
+   char table entries should never escape to Lisp */
 
-#define CHAR_TABLE_TYPE(ct) ((ct)->type)
-#define XCHAR_TABLE_TYPE(ct) CHAR_TABLE_TYPE (XCHAR_TABLE (ct))
+#endif /* MULE */
 
 enum char_table_type
 {
@@ -81,16 +154,25 @@ enum char_table_type
   CHAR_TABLE_TYPE_CHAR
 };
 
+#ifndef UTF2000
 #ifdef MULE
 #define NUM_ASCII_CHARS 160
 #else
 #define NUM_ASCII_CHARS 256
 #endif
+#endif
 
 struct Lisp_Char_Table
 {
   struct lcrecord_header header;
 
+#ifdef UTF2000
+  Lisp_Object table;
+  Lisp_Object default_value;
+  Lisp_Object name;
+  Lisp_Object db;
+  unsigned char unloaded;
+#else
   Lisp_Object ascii[NUM_ASCII_CHARS];
 
 #ifdef MULE
@@ -122,26 +204,71 @@ struct Lisp_Char_Table
   Lisp_Object level1[NUM_LEADING_BYTES];
 
 #endif /* MULE */
+#endif /* non UTF2000 */
 
   enum char_table_type type;
 
+#ifndef UTF2000
   /* stuff used for syntax tables */
   Lisp_Object mirror_table;
+#endif
   Lisp_Object next_table; /* DO NOT mark through this. */
 };
+typedef struct Lisp_Char_Table Lisp_Char_Table;
 
-#ifdef MULE
+DECLARE_LRECORD (char_table, Lisp_Char_Table);
+#define XCHAR_TABLE(x) XRECORD (x, char_table, Lisp_Char_Table)
+#define XSETCHAR_TABLE(x, p) XSETRECORD (x, p, char_table)
+#define CHAR_TABLEP(x) RECORDP (x, char_table)
+#define CHECK_CHAR_TABLE(x) CHECK_RECORD (x, char_table)
+#define CONCHECK_CHAR_TABLE(x) CONCHECK_RECORD (x, char_table)
 
-Lisp_Object get_non_ascii_char_table_value (struct Lisp_Char_Table *ct,
-                                          int leading_byte,
-                                          Emchar c);
+#define CHAR_TABLE_TYPE(ct) ((ct)->type)
+#define XCHAR_TABLE_TYPE(ct) CHAR_TABLE_TYPE (XCHAR_TABLE (ct))
+
+#ifdef UTF2000
+
+#define CHAR_TABLE_NAME(ct) ((ct)->name)
+#define XCHAR_TABLE_NAME(ct) CHAR_TABLE_NAME (XCHAR_TABLE (ct))
 
-INLINE Lisp_Object
-CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (struct Lisp_Char_Table *ct, Emchar ch);
-INLINE Lisp_Object
-CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (struct Lisp_Char_Table *ct, Emchar ch)
+#define CHAR_TABLE_UNLOADED(ct) ((ct)->unloaded)
+#define XCHAR_TABLE_UNLOADED(ct) CHAR_TABLE_UNLOADED (XCHAR_TABLE (ct))
+
+INLINE_HEADER Lisp_Object
+CHAR_TABLE_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch);
+INLINE_HEADER Lisp_Object
+CHAR_TABLE_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch)
 {
-  unsigned char lb = CHAR_LEADING_BYTE (ch);
+  Lisp_Object val = get_byte_table (get_byte_table
+                                   (get_byte_table
+                                    (get_byte_table
+                                     (ct->table,
+                                      (unsigned char)(ch >> 24)),
+                                     (unsigned char) (ch >> 16)),
+                                    (unsigned char)  (ch >> 8)),
+                                   (unsigned char)    ch);
+  if (UNBOUNDP (val))
+    return ct->default_value;
+  else
+    return val;
+}
+
+#elif defined(MULE)
+
+Lisp_Object get_non_ascii_char_table_value (Lisp_Char_Table *ct,
+                                           Charset_ID leading_byte,
+                                           Emchar c);
+
+INLINE_HEADER Lisp_Object
+CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch);
+INLINE_HEADER Lisp_Object
+CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (Lisp_Char_Table *ct, Emchar ch)
+{
+#ifdef UTF2000
+  Charset_ID lb = CHAR_CHARSET_ID (ch);
+#else
+  Charset_ID lb = CHAR_LEADING_BYTE (ch);
+#endif
   if (!CHAR_TABLE_ENTRYP ((ct)->level1[lb - MIN_LEADING_BYTE]))
     return (ct)->level1[lb - MIN_LEADING_BYTE];
   else
@@ -159,9 +286,15 @@ CHAR_TABLE_NON_ASCII_VALUE_UNSAFE (struct Lisp_Char_Table *ct, Emchar ch)
 
 #endif /* not MULE */
 
+#define XCHAR_TABLE_VALUE_UNSAFE(ct, ch) \
+  CHAR_TABLE_VALUE_UNSAFE (XCHAR_TABLE (ct), ch)
+
 enum chartab_range_type
 {
   CHARTAB_RANGE_ALL,
+#ifdef UTF2000
+  CHARTAB_RANGE_DEFAULT,
+#endif
 #ifdef MULE
   CHARTAB_RANGE_CHARSET,
   CHARTAB_RANGE_ROW,
@@ -177,27 +310,115 @@ struct chartab_range
   int row;
 };
 
-void fill_char_table (struct Lisp_Char_Table *ct, Lisp_Object value);
-void put_char_table (struct Lisp_Char_Table *ct, struct chartab_range *range,
+void fill_char_table (Lisp_Char_Table *ct, Lisp_Object value);
+void put_char_table (Lisp_Char_Table *ct, struct chartab_range *range,
                     Lisp_Object val);
-int map_char_table (struct Lisp_Char_Table *ct,
+Lisp_Object get_char_table (Emchar, Lisp_Char_Table *);
+int map_char_table (Lisp_Char_Table *ct,
                    struct chartab_range *range,
                    int (*fn) (struct chartab_range *range,
                               Lisp_Object val, void *arg),
                    void *arg);
-void prune_syntax_tables (int (*obj_marked_p) (Lisp_Object));
+void prune_syntax_tables (void);
 
 EXFUN (Fcopy_char_table, 1);
 EXFUN (Fmake_char_table, 1);
 EXFUN (Fput_char_table, 3);
+EXFUN (Fget_char_table, 2);
 
 extern Lisp_Object Vall_syntax_tables;
 
 \f
+#ifdef UTF2000
+
+INLINE_HEADER void
+put_char_id_table_0 (Lisp_Char_Table* cit, Emchar code, Lisp_Object value);
+INLINE_HEADER void
+put_char_id_table_0 (Lisp_Char_Table* cit, Emchar code, Lisp_Object value)
+{
+  Lisp_Object table1, table2, table3, table4;
+       
+  table1 = cit->table;
+  table2 = get_byte_table (table1, (unsigned char)(code >> 24));
+  table3 = get_byte_table (table2, (unsigned char)(code >> 16));
+  table4 = get_byte_table (table3, (unsigned char)(code >>  8));
+
+  table4     = put_byte_table (table4, (unsigned char) code, value);
+  table3     = put_byte_table (table3, (unsigned char)(code >>  8), table4);
+  table2     = put_byte_table (table2, (unsigned char)(code >> 16), table3);
+  cit->table = put_byte_table (table1, (unsigned char)(code >> 24), table2);
+}
+
+#ifdef HAVE_CHISE_CLIENT
+extern Lisp_Object Qsystem_char_id;
+
+Lisp_Object
+char_attribute_system_db_file (Lisp_Object key_type, Lisp_Object attribute,
+                              int writing_mode);
+
+Lisp_Object load_char_attribute_maybe (Lisp_Char_Table* cit, Emchar ch);
+#endif
+
+INLINE_HEADER Lisp_Object
+get_char_id_table_0 (Lisp_Char_Table* cit, Emchar ch);
+INLINE_HEADER Lisp_Object
+get_char_id_table_0 (Lisp_Char_Table* cit, Emchar ch)
+{
+  return get_byte_table (get_byte_table
+                        (get_byte_table
+                         (get_byte_table
+                          (cit->table,
+                           (unsigned char)(ch >> 24)),
+                          (unsigned char) (ch >> 16)),
+                         (unsigned char)  (ch >> 8)),
+                        (unsigned char)    ch);
+}
+
+INLINE_HEADER Lisp_Object
+get_char_id_table (Lisp_Char_Table* cit, Emchar ch);
+INLINE_HEADER Lisp_Object
+get_char_id_table (Lisp_Char_Table* cit, Emchar ch)
+{
+  Lisp_Object val = get_char_id_table_0 (cit, ch);
+
+#ifdef HAVE_CHISE_CLIENT
+  if (EQ (val, Qunloaded))
+    {
+      val = load_char_attribute_maybe (cit, ch);
+      put_char_id_table_0 (cit, ch, val);
+    }
+#endif
+  if (UNBOUNDP (val))
+    return cit->default_value;
+  else
+    return val;
+}
+
+void
+decode_char_table_range (Lisp_Object range, struct chartab_range *outrange);
+
+INLINE_HEADER void
+put_char_id_table (Lisp_Char_Table* table,
+                  Lisp_Object character, Lisp_Object value);
+INLINE_HEADER void
+put_char_id_table (Lisp_Char_Table* table,
+                  Lisp_Object character, Lisp_Object value)
+{
+  struct chartab_range range;
+
+  decode_char_table_range (character, &range);
+  put_char_table (table, &range, value);
+}
+
+
+EXFUN (Fget_char_attribute, 3);
+
+#endif
+\f
 
 #ifdef MULE
 int check_category_char(Emchar ch, Lisp_Object ctbl,
-                       unsigned int designator, unsigned int not);
+                       unsigned int designator, unsigned int not_p);
 
 extern Lisp_Object Vstandard_category_table;
 
@@ -229,4 +450,4 @@ extern Lisp_Object Vstandard_category_table;
 
 #endif /* MULE */
 
-#endif /* _MULE_CHARTAB_H */
+#endif /* INCLUDED_chartab_h_ */