Copyright (C) 1995, 1996 Ben Wing.
Copyright (C) 1995, 1997, 1999 Electrotechnical Laboratory, JAPAN.
Licensed to the Free Software Foundation.
- Copyright (C) 1999,2000,2001,2002 MORIOKA Tomohiko
+ Copyright (C) 1999,2000,2001,2002,2003 MORIOKA Tomohiko
This file is part of XEmacs.
loosely based on the original Mule.
Jareth Hein: fixed a couple of bugs in the implementation, and
added regex support for categories with check_category_at
+ MORIOKA Tomohiko: Rewritten for XEmacs UTF-2000
*/
#include <config.h>
\f
#ifdef UTF2000
-#if defined(HAVE_DATABASE)
-EXFUN (Fload_char_attribute_table, 1);
+EXFUN (Fchar_refs_simplify_char_specs, 1);
+extern Lisp_Object Qideographic_structure;
+
EXFUN (Fmap_char_attribute, 3);
+
+#if defined(HAVE_CHISE_CLIENT)
+EXFUN (Fload_char_attribute_table, 1);
+
+Lisp_Object Vchar_db_stingy_mode;
#endif
#define BT_UINT8_MIN 0
return retval;
}
-#ifdef HAVE_DATABASE
+#ifdef HAVE_CHISE_CLIENT
static void
save_uint8_byte_table (Lisp_Uint8_Byte_Table *ct, Lisp_Char_Table* root,
Lisp_Object db,
- Emchar ofs, int place)
+ Emchar ofs, int place,
+ Lisp_Object (*filter)(Lisp_Object value))
{
struct chartab_range rainj;
int i, retval;
Fprin1_to_string (UINT8_DECODE (ct->property[i]),
Qnil),
db, Qt);
- put_char_id_table (root, make_char (c), Qunloaded);
}
}
else
return retval;
}
-#ifdef HAVE_DATABASE
+#ifdef HAVE_CHISE_CLIENT
static void
save_uint16_byte_table (Lisp_Uint16_Byte_Table *ct, Lisp_Char_Table* root,
Lisp_Object db,
- Emchar ofs, int place)
+ Emchar ofs, int place,
+ Lisp_Object (*filter)(Lisp_Object value))
{
struct chartab_range rainj;
int i, retval;
Fprin1_to_string (UINT16_DECODE (ct->property[i]),
Qnil),
db, Qt);
- put_char_id_table (root, make_char (c), Qunloaded);
}
}
else
return retval;
}
-#ifdef HAVE_DATABASE
+#ifdef HAVE_CHISE_CLIENT
static void
save_byte_table (Lisp_Byte_Table *ct, Lisp_Char_Table* root,
Lisp_Object db,
- Emchar ofs, int place)
+ Emchar ofs, int place,
+ Lisp_Object (*filter)(Lisp_Object value))
{
int i, retval;
Lisp_Object v;
if (UINT8_BYTE_TABLE_P (v))
{
save_uint8_byte_table (XUINT8_BYTE_TABLE(v), root, db,
- c, place - 1);
+ c, place - 1, filter);
c += unit;
}
else if (UINT16_BYTE_TABLE_P (v))
{
save_uint16_byte_table (XUINT16_BYTE_TABLE(v), root, db,
- c, place - 1);
+ c, place - 1, filter);
c += unit;
}
else if (BYTE_TABLE_P (v))
{
save_byte_table (XBYTE_TABLE(v), root, db,
- c, place - 1);
+ c, place - 1, filter);
c += unit;
}
else if (EQ (v, Qunloaded))
struct chartab_range rainj;
Emchar c1 = c + unit;
+ if (filter != NULL)
+ v = (*filter)(v);
+
rainj.type = CHARTAB_RANGE_CHAR;
for (; c < c1 && retval == 0; c++)
Fput_database (Fprin1_to_string (make_char (c), Qnil),
Fprin1_to_string (v, Qnil),
db, Qt);
- put_char_id_table (root, make_char (c), Qunloaded);
}
}
else
}
-Lisp_Object Vcharacter_composition_table;
-Lisp_Object Vcharacter_variant_table;
-
-
Lisp_Object Qsystem_char_id;
+Lisp_Object Qcomposition;
Lisp_Object Q_decomposition;
Lisp_Object Qto_ucs;
Lisp_Object Q_ucs;
*/
(list))
{
- Lisp_Object table = Vcharacter_composition_table;
- Lisp_Object rest = list;
+ Lisp_Object base, modifier;
+ Lisp_Object rest;
- while (CONSP (rest))
+ if (!CONSP (list))
+ signal_simple_error ("Invalid value for composition", list);
+ base = Fcar (list);
+ rest = Fcdr (list);
+ while (!NILP (rest))
{
- Lisp_Object v = Fcar (rest);
- Lisp_Object ret;
- Emchar c = to_char_id (v, "Invalid value for composition", list);
-
- ret = get_char_id_table (XCHAR_TABLE(table), c);
-
+ if (!CHARP (base))
+ return Qnil;
+ if (!CONSP (rest))
+ signal_simple_error ("Invalid value for composition", list);
+ modifier = Fcar (rest);
rest = Fcdr (rest);
- if (NILP (rest))
- {
- if (!CHAR_TABLEP (ret))
- return ret;
- else
- return Qt;
- }
- else if (!CONSP (rest))
- break;
- else if (CHAR_TABLEP (ret))
- table = ret;
- else
- signal_simple_error ("Invalid table is found with", list);
+ base = Fcdr (Fassq (modifier,
+ Fget_char_attribute (base, Qcomposition, Qnil)));
}
- signal_simple_error ("Invalid value for composition", list);
+ return base;
}
DEFUN ("char-variants", Fchar_variants, 1, 1, 0, /*
Lisp_Object ret;
CHECK_CHAR (character);
- ret = get_char_id_table (XCHAR_TABLE(Vcharacter_variant_table),
- XCHAR(character));
+ ret = Fget_char_attribute (character, Q_ucs_variants, Qnil);
if (CONSP (ret))
return Fcopy_list (ret);
else
get_char_table (Emchar ch, Lisp_Char_Table *ct)
{
#ifdef UTF2000
- return get_char_id_table (ct, ch);
+ {
+ Lisp_Object ret = get_char_id_table (ct, ch);
+
+#ifdef HAVE_CHISE_CLIENT
+ if (NILP (ret))
+ {
+ if (EQ (CHAR_TABLE_NAME (ct), Qdowncase))
+ ret = Fget_char_attribute (make_char (ch), Q_lowercase, Qnil);
+ else if (EQ (CHAR_TABLE_NAME (ct), Qflippedcase))
+ ret = Fget_char_attribute (make_char (ch), Q_uppercase, Qnil);
+ if (CONSP (ret))
+ {
+ ret = XCAR (ret);
+ if (CONSP (ret))
+ ret = Ffind_char (ret);
+ }
+ }
+#endif
+ return ret;
+ }
#elif defined(MULE)
{
Lisp_Object charset;
case CHARTAB_RANGE_CHARSET:
#ifdef UTF2000
{
- Emchar c;
Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (range->charset);
/* printf ("put-char-table: range = charset: %d\n",
*/
if ( CHAR_TABLEP (encoding_table) )
{
-#if 1
char_attribute_table_to_put = ct;
value_to_put = val;
Fmap_char_attribute (Qput_char_table_map_function,
XCHAR_TABLE_NAME (encoding_table),
Qnil);
-#else
- for (c = 0; c < 1 << 24; c++)
- {
- if ( INTP (get_char_id_table (XCHAR_TABLE(encoding_table),
- c)) )
- put_char_id_table_0 (ct, c, val);
- }
-#endif
}
+#if 0
else
{
+ Emchar c;
+
for (c = 0; c < 1 << 24; c++)
{
if ( charset_code_point (range->charset, c) >= 0 )
put_char_id_table_0 (ct, c, val);
}
}
+#endif
}
#else
if (EQ (range->charset, Vcharset_ascii))
{
Emchar ch = DECODE_CHAR (range->charset, (range->row << 8) | i);
- if ( charset_code_point (range->charset, ch) >= 0 )
+ if ( charset_code_point (range->charset, ch, 0) >= 0 )
put_char_id_table_0 (ct, ch, val);
}
}
struct chartab_range rainj;
struct map_char_table_for_charset_arg mcarg;
-#ifdef HAVE_DATABASE
+#ifdef HAVE_CHISE_CLIENT
if (XCHAR_TABLE_UNLOADED(encoding_table))
Fload_char_attribute_table (XCHAR_TABLE_NAME (encoding_table));
#endif
{
Emchar ch = DECODE_CHAR (range->charset, (range->row << 8) | i);
- if ( charset_code_point (range->charset, ch) >= 0 )
+ if ( charset_code_point (range->charset, ch, 0) >= 0 )
{
Lisp_Object val
= get_byte_table (get_byte_table
return default_value;
}
-DEFUN ("put-char-attribute", Fput_char_attribute, 3, 3, 0, /*
-Store CHARACTER's ATTRIBUTE with VALUE.
-*/
- (character, attribute, value))
+void put_char_composition (Lisp_Object character, Lisp_Object value);
+void
+put_char_composition (Lisp_Object character, Lisp_Object value)
{
- Lisp_Object ccs = Ffind_charset (attribute);
+ if (!CONSP (value))
+ signal_simple_error ("Invalid value for ->decomposition",
+ value);
- if (!NILP (ccs))
- {
- CHECK_CHAR (character);
- value = put_char_ccs_code_point (character, ccs, value);
- }
- else if (EQ (attribute, Q_decomposition))
+ if (CONSP (Fcdr (value)))
{
- Lisp_Object seq;
-
- CHECK_CHAR (character);
- if (!CONSP (value))
- signal_simple_error ("Invalid value for ->decomposition",
- value);
-
- if (CONSP (Fcdr (value)))
+ if (NILP (Fcdr (Fcdr (value))))
{
- Lisp_Object rest = value;
- Lisp_Object table = Vcharacter_composition_table;
- size_t len;
- int i = 0;
+ Lisp_Object base = Fcar (value);
+ Lisp_Object modifier = Fcar (Fcdr (value));
- GET_EXTERNAL_LIST_LENGTH (rest, len);
- seq = make_vector (len, Qnil);
-
- while (CONSP (rest))
+ if (INTP (base))
{
- Lisp_Object v = Fcar (rest);
- Lisp_Object ntable;
- Emchar c
- = to_char_id (v, "Invalid value for ->decomposition", value);
-
- if (c < 0)
- XVECTOR_DATA(seq)[i++] = v;
- else
- XVECTOR_DATA(seq)[i++] = make_char (c);
- rest = Fcdr (rest);
- if (!CONSP (rest))
- {
- put_char_id_table (XCHAR_TABLE(table),
- make_char (c), character);
- break;
- }
+ base = make_char (XINT (base));
+ Fsetcar (value, base);
+ }
+ if (INTP (modifier))
+ {
+ modifier = make_char (XINT (modifier));
+ Fsetcar (Fcdr (value), modifier);
+ }
+ if (CHARP (base))
+ {
+ Lisp_Object alist
+ = Fget_char_attribute (base, Qcomposition, Qnil);
+ Lisp_Object ret = Fassq (modifier, alist);
+
+ if (NILP (ret))
+ Fput_char_attribute (base, Qcomposition,
+ Fcons (Fcons (modifier, character),
+ alist));
else
- {
- ntable = get_char_id_table (XCHAR_TABLE(table), c);
- if (!CHAR_TABLEP (ntable))
- {
- ntable = make_char_id_table (Qnil);
- put_char_id_table (XCHAR_TABLE(table),
- make_char (c), ntable);
- }
- table = ntable;
- }
+ Fsetcdr (ret, character);
}
}
- else
+ }
+ else
+ {
+ Lisp_Object v = Fcar (value);
+
+ if (INTP (v))
{
- Lisp_Object v = Fcar (value);
+ Emchar c = XINT (v);
+ Lisp_Object ret
+ = Fget_char_attribute (make_char (c), Q_ucs_variants, Qnil);
- if (INTP (v))
+ if (!CONSP (ret))
{
- Emchar c = XINT (v);
- Lisp_Object ret
- = get_char_id_table (XCHAR_TABLE(Vcharacter_variant_table),
- c);
-
- if (!CONSP (ret))
- {
- put_char_id_table (XCHAR_TABLE(Vcharacter_variant_table),
- make_char (c), Fcons (character, Qnil));
- }
- else if (NILP (Fmemq (v, ret)))
- {
- put_char_id_table (XCHAR_TABLE(Vcharacter_variant_table),
- make_char (c), Fcons (character, ret));
- }
+ Fput_char_attribute (make_char (c), Q_ucs_variants,
+ Fcons (character, Qnil));
+ }
+ else if (NILP (Fmemq (character, ret)))
+ {
+ Fput_char_attribute (make_char (c), Q_ucs_variants,
+ Fcons (character, ret));
}
- seq = make_vector (1, v);
}
- value = seq;
}
+}
+
+DEFUN ("put-char-attribute", Fput_char_attribute, 3, 3, 0, /*
+Store CHARACTER's ATTRIBUTE with VALUE.
+*/
+ (character, attribute, value))
+{
+ Lisp_Object ccs = Ffind_charset (attribute);
+
+ CHECK_CHAR (character);
+
+ if (!NILP (ccs))
+ {
+ value = put_char_ccs_code_point (character, ccs, value);
+ attribute = XCHARSET_NAME (ccs);
+ }
+ else if (EQ (attribute, Q_decomposition))
+ put_char_composition (character, value);
else if (EQ (attribute, Qto_ucs) || EQ (attribute, Q_ucs))
{
Lisp_Object ret;
Emchar c;
- CHECK_CHAR (character);
if (!INTP (value))
- signal_simple_error ("Invalid value for ->ucs", value);
+ signal_simple_error ("Invalid value for =>ucs", value);
c = XINT (value);
- ret = get_char_id_table (XCHAR_TABLE(Vcharacter_variant_table), c);
+ ret = Fget_char_attribute (make_char (c), Q_ucs_variants, Qnil);
if (!CONSP (ret))
{
- put_char_id_table (XCHAR_TABLE(Vcharacter_variant_table),
- make_char (c), Fcons (character, Qnil));
+ Fput_char_attribute (make_char (c), Q_ucs_variants,
+ Fcons (character, Qnil));
}
else if (NILP (Fmemq (character, ret)))
{
- put_char_id_table (XCHAR_TABLE(Vcharacter_variant_table),
- make_char (c), Fcons (character, ret));
+ Fput_char_attribute (make_char (c), Q_ucs_variants,
+ Fcons (character, ret));
}
#if 0
if (EQ (attribute, Q_ucs))
attribute = Qto_ucs;
#endif
}
+#if 0
+ else if (EQ (attribute, Qideographic_structure))
+ value = Fcopy_sequence (Fchar_refs_simplify_char_specs (value));
+#endif
{
Lisp_Object table = Fgethash (attribute,
Vchar_attribute_hash_table,
{
table = make_char_id_table (Qunbound);
Fputhash (attribute, table, Vchar_attribute_hash_table);
-#ifdef HAVE_DATABASE
+#ifdef HAVE_CHISE_CLIENT
XCHAR_TABLE_NAME (table) = attribute;
#endif
}
return Qnil;
}
+#ifdef HAVE_CHISE_CLIENT
Lisp_Object
char_attribute_system_db_file (Lisp_Object key_type, Lisp_Object attribute,
int writing_mode)
return Fexpand_file_name (Fsymbol_name (attribute), db_dir);
#endif
}
-
+
DEFUN ("save-char-attribute-table", Fsave_char_attribute_table, 1, 1, 0, /*
Save values of ATTRIBUTE into database file.
*/
(attribute))
{
-#ifdef HAVE_DATABASE
+#ifdef HAVE_CHISE_CLIENT
Lisp_Object table = Fgethash (attribute,
Vchar_attribute_hash_table, Qunbound);
Lisp_Char_Table *ct;
db = Fopen_database (db_file, Qnil, Qnil, build_string ("w+"), Qnil);
if (!NILP (db))
{
+ Lisp_Object (*filter)(Lisp_Object value);
+
+ if (EQ (attribute, Qideographic_structure))
+ filter = &Fchar_refs_simplify_char_specs;
+ else
+ filter = NULL;
+
if (UINT8_BYTE_TABLE_P (ct->table))
- save_uint8_byte_table (XUINT8_BYTE_TABLE(ct->table), ct, db, 0, 3);
+ save_uint8_byte_table (XUINT8_BYTE_TABLE(ct->table), ct, db,
+ 0, 3, filter);
else if (UINT16_BYTE_TABLE_P (ct->table))
- save_uint16_byte_table (XUINT16_BYTE_TABLE(ct->table), ct, db, 0, 3);
+ save_uint16_byte_table (XUINT16_BYTE_TABLE(ct->table), ct, db,
+ 0, 3, filter);
else if (BYTE_TABLE_P (ct->table))
- save_byte_table (XBYTE_TABLE(ct->table), ct, db, 0, 3);
+ save_byte_table (XBYTE_TABLE(ct->table), ct, db, 0, 3, filter);
Fclose_database (db);
return Qt;
}
#endif
}
+DEFUN ("mount-char-attribute-table", Fmount_char_attribute_table, 1, 1, 0, /*
+Mount database file on char-attribute-table ATTRIBUTE.
+*/
+ (attribute))
+{
+#ifdef HAVE_CHISE_CLIENT
+ Lisp_Object table = Fgethash (attribute,
+ Vchar_attribute_hash_table, Qunbound);
+
+ if (UNBOUNDP (table))
+ {
+ Lisp_Char_Table *ct;
+
+ table = make_char_id_table (Qunbound);
+ Fputhash (attribute, table, Vchar_attribute_hash_table);
+ XCHAR_TABLE_NAME(table) = attribute;
+ ct = XCHAR_TABLE (table);
+ ct->table = Qunloaded;
+ XCHAR_TABLE_UNLOADED(table) = 1;
+ ct->db = Qnil;
+ return Qt;
+ }
+#endif
+ return Qnil;
+}
+
DEFUN ("close-char-attribute-table", Fclose_char_attribute_table, 1, 1, 0, /*
Close database of ATTRIBUTE.
*/
(attribute))
{
-#ifdef HAVE_DATABASE
+#ifdef HAVE_CHISE_CLIENT
Lisp_Object table = Fgethash (attribute,
Vchar_attribute_hash_table, Qunbound);
Lisp_Char_Table *ct;
*/
(attribute))
{
-#ifdef HAVE_DATABASE
+#ifdef HAVE_CHISE_CLIENT
Lisp_Object table = Fgethash (attribute,
Vchar_attribute_hash_table, Qunbound);
Lisp_Char_Table *ct;
return Qnil;
}
-#ifdef HAVE_DATABASE
Lisp_Object
load_char_attribute_maybe (Lisp_Char_Table* cit, Emchar ch)
{
Lisp_Object db_file
= char_attribute_system_db_file (Qsystem_char_id, attribute, 0);
- cit->db = Fopen_database (db_file, Qnil, Qnil, build_string ("r"), Qnil);
+ cit->db = Fopen_database (db_file, Qnil, Qnil,
+ build_string ("r"), Qnil);
}
if (!NILP (cit->db))
{
val = Fread (val);
else
val = Qunbound;
+ if (!NILP (Vchar_db_stingy_mode))
+ {
+ Fclose_database (cit->db);
+ cit->db = Qnil;
+ }
return val;
}
}
{
Lisp_Object c = Fread (key);
Emchar code = XCHAR (c);
- Lisp_Object ret = get_char_id_table (char_attribute_table_to_load, code);
+ Lisp_Object ret = get_char_id_table_0 (char_attribute_table_to_load, code);
if (EQ (ret, Qunloaded))
put_char_id_table_0 (char_attribute_table_to_load, code, Fread (value));
return Qnil;
}
-#endif
DEFUN ("load-char-attribute-table", Fload_char_attribute_table, 1, 1, 0, /*
Load values of ATTRIBUTE into database file.
*/
(attribute))
{
-#ifdef HAVE_DATABASE
Lisp_Object table = Fgethash (attribute,
Vchar_attribute_hash_table,
Qunbound);
Lisp_Object db_file
= char_attribute_system_db_file (Qsystem_char_id, attribute, 0);
- ct->db = Fopen_database (db_file, Qnil, Qnil, build_string ("r"), Qnil);
+ ct->db = Fopen_database (db_file, Qnil, Qnil,
+ build_string ("r"), Qnil);
}
if (!NILP (ct->db))
{
}
}
return Qnil;
-#endif
}
+#endif
DEFUN ("map-char-attribute", Fmap_char_attribute, 2, 3, 0, /*
Map FUNCTION over entries in ATTRIBUTE, calling it with two args,
if (NILP (range))
range = Qt;
decode_char_table_range (range, &rainj);
-#ifdef HAVE_DATABASE
+#ifdef HAVE_CHISE_CLIENT
if (CHAR_TABLE_UNLOADED(ct))
Fload_char_attribute_table (attribute);
#endif
(attributes))
{
Lisp_Object rest = attributes;
- Lisp_Object code = Fcdr (Fassq (Qucs, attributes));
+ Lisp_Object code = Fcdr (Fassq (Qmap_ucs, attributes));
Lisp_Object character;
if (NILP (code))
+ code = Fcdr (Fassq (Qucs, attributes));
+ if (NILP (code))
{
while (CONSP (rest))
{
defsymbol (&Qto_ucs, "=>ucs");
defsymbol (&Q_ucs, "->ucs");
defsymbol (&Q_ucs_variants, "->ucs-variants");
+ defsymbol (&Qcomposition, "composition");
defsymbol (&Q_decomposition, "->decomposition");
defsymbol (&Qcompat, "compat");
defsymbol (&Qisolated, "isolated");
DEFSUBR (Ffind_char_attribute_table);
defsymbol (&Qput_char_table_map_function, "put-char-table-map-function");
DEFSUBR (Fput_char_table_map_function);
+#ifdef HAVE_CHISE_CLIENT
DEFSUBR (Fsave_char_attribute_table);
+ DEFSUBR (Fmount_char_attribute_table);
DEFSUBR (Freset_char_attribute_table);
DEFSUBR (Fclose_char_attribute_table);
-#ifdef HAVE_DATABASE
defsymbol (&Qload_char_attribute_table_map_function,
"load-char-attribute-table-map-function");
DEFSUBR (Fload_char_attribute_table_map_function);
-#endif
DEFSUBR (Fload_char_attribute_table);
+#endif
DEFSUBR (Fchar_attribute_alist);
DEFSUBR (Fget_char_attribute);
DEFSUBR (Fput_char_attribute);
vars_of_chartab (void)
{
#ifdef UTF2000
- staticpro (&Vcharacter_composition_table);
- Vcharacter_composition_table = make_char_id_table (Qnil);
-
- staticpro (&Vcharacter_variant_table);
- Vcharacter_variant_table = make_char_id_table (Qunbound);
+#ifdef HAVE_CHISE_CLIENT
+ DEFVAR_LISP ("char-db-stingy-mode", &Vchar_db_stingy_mode /*
+*/ );
+ Vchar_db_stingy_mode = Qt;
+#endif /* HAVE_CHISE_CLIENT */
#endif
/* DO NOT staticpro this. It works just like Vweak_hash_tables. */
Vall_syntax_tables = Qnil;
staticpro (&Vchar_attribute_hash_table);
Vchar_attribute_hash_table
= make_lisp_hash_table (16, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
-#ifdef HAVE_DATABASE
- Fputhash (Q_ucs_variants, Vcharacter_variant_table,
- Vchar_attribute_hash_table);
- XCHAR_TABLE_NAME (Vcharacter_variant_table) = Q_ucs_variants;
-#endif /* HAVE_DATABASE */
#endif /* UTF2000 */
#ifdef MULE
/* Set this now, so first buffer creation can refer to it. */