+#ifdef UTF2000
+DEFUN ("charset-mapping-table", Fcharset_mapping_table, 1, 1, 0, /*
+Return mapping-table of CHARSET.
+*/
+ (charset))
+{
+ return XCHARSET_DECODING_TABLE (Fget_charset (charset));
+}
+
+DEFUN ("set-charset-mapping-table", Fset_charset_mapping_table, 2, 2, 0, /*
+Set mapping-table of CHARSET to TABLE.
+*/
+ (charset, table))
+{
+ struct Lisp_Charset *cs;
+ int i;
+ int byte_offset;
+
+ charset = Fget_charset (charset);
+ cs = XCHARSET (charset);
+
+ if (NILP (table))
+ {
+ CHARSET_DECODING_TABLE(cs) = Qnil;
+ return table;
+ }
+ else if (VECTORP (table))
+ {
+ int ccs_len = CHARSET_BYTE_SIZE (cs);
+ int ret = decoding_table_check_elements (table,
+ CHARSET_DIMENSION (cs),
+ ccs_len);
+ if (ret)
+ {
+ if (ret == -1)
+ signal_simple_error ("Too big table", table);
+ else if (ret == -2)
+ signal_simple_error ("Invalid element is found", table);
+ else
+ signal_simple_error ("Something wrong", table);
+ }
+ CHARSET_DECODING_TABLE(cs) = Qnil;
+ }
+ else
+ signal_error (Qwrong_type_argument,
+ list2 (build_translated_string ("vector-or-nil-p"),
+ table));
+
+ byte_offset = CHARSET_BYTE_OFFSET (cs);
+ switch (CHARSET_DIMENSION (cs))
+ {
+ case 1:
+ for (i = 0; i < XVECTOR_LENGTH (table); i++)
+ {
+ Lisp_Object c = XVECTOR_DATA(table)[i];
+
+ if (CHARP (c))
+ Fput_char_attribute (c, XCHARSET_NAME (charset),
+ make_int (i + byte_offset));
+ }
+ break;
+ case 2:
+ for (i = 0; i < XVECTOR_LENGTH (table); i++)
+ {
+ Lisp_Object v = XVECTOR_DATA(table)[i];
+
+ if (VECTORP (v))
+ {
+ int j;
+
+ for (j = 0; j < XVECTOR_LENGTH (v); j++)
+ {
+ Lisp_Object c = XVECTOR_DATA(v)[j];
+
+ if (CHARP (c))
+ Fput_char_attribute
+ (c, XCHARSET_NAME (charset),
+ make_int ( ( (i + byte_offset) << 8 )
+ | (j + byte_offset)
+ ) );
+ }
+ }
+ else if (CHARP (v))
+ Fput_char_attribute (v, XCHARSET_NAME (charset),
+ make_int (i + byte_offset));
+ }
+ break;
+ }
+ return table;
+}
+
+#ifdef HAVE_CHISE
+DEFUN ("save-charset-mapping-table", Fsave_charset_mapping_table, 1, 1, 0, /*
+Save mapping-table of CHARSET.
+*/
+ (charset))
+{
+ struct Lisp_Charset *cs;
+ int byte_min, byte_max;
+#ifdef HAVE_LIBCHISE
+ CHISE_CCS dt_ccs;
+#else /* HAVE_LIBCHISE */
+ Lisp_Object db;
+ Lisp_Object db_file;
+#endif /* not HAVE_LIBCHISE */
+
+ charset = Fget_charset (charset);
+ cs = XCHARSET (charset);
+
+#ifdef HAVE_LIBCHISE
+ if ( open_chise_data_source_maybe () )
+ return -1;
+
+ dt_ccs
+ = chise_ds_get_ccs (default_chise_data_source,
+ XSTRING_DATA (Fsymbol_name (XCHARSET_NAME(charset))));
+ if (dt_ccs == NULL)
+ {
+ printf ("Can't open decoding-table %s\n",
+ XSTRING_DATA (Fsymbol_name (XCHARSET_NAME(charset))));
+ return -1;
+ }
+#else /* HAVE_LIBCHISE */
+ db_file = char_attribute_system_db_file (CHARSET_NAME (cs),
+ Qsystem_char_id, 1);
+ db = Fopen_database (db_file, Qnil, Qnil, build_string ("w+"), Qnil);
+#endif /* not HAVE_LIBCHISE */
+
+ byte_min = CHARSET_BYTE_OFFSET (cs);
+ byte_max = byte_min + CHARSET_BYTE_SIZE (cs);
+ switch (CHARSET_DIMENSION (cs))
+ {
+ case 1:
+ {
+ Lisp_Object table_c = XCHARSET_DECODING_TABLE (charset);
+ int cell;
+
+ for (cell = byte_min; cell < byte_max; cell++)
+ {
+ Lisp_Object c = get_ccs_octet_table (table_c, charset, cell);
+
+ if (CHARP (c))
+ {
+#ifdef HAVE_LIBCHISE
+ chise_ccs_set_decoded_char (dt_ccs, cell, XCHAR (c));
+#else /* HAVE_LIBCHISE */
+ Fput_database (Fprin1_to_string (make_int (cell), Qnil),
+ Fprin1_to_string (c, Qnil),
+ db, Qt);
+#endif /* not HAVE_LIBCHISE */
+ }
+ }
+ }
+ break;
+ case 2:
+ {
+ Lisp_Object table_r = XCHARSET_DECODING_TABLE (charset);
+ int row;
+
+ for (row = byte_min; row < byte_max; row++)
+ {
+ Lisp_Object table_c = get_ccs_octet_table (table_r, charset, row);
+ int cell;
+
+ for (cell = byte_min; cell < byte_max; cell++)
+ {
+ Lisp_Object c = get_ccs_octet_table (table_c, charset, cell);
+
+ if (CHARP (c))
+ {
+#ifdef HAVE_LIBCHISE
+ chise_ccs_set_decoded_char
+ (dt_ccs,
+ (row << 8) | cell, XCHAR (c));
+#else /* HAVE_LIBCHISE */
+ Fput_database (Fprin1_to_string (make_int ((row << 8)
+ | cell),
+ Qnil),
+ Fprin1_to_string (c, Qnil),
+ db, Qt);
+#endif /* not HAVE_LIBCHISE */
+ }
+ }
+ }
+ }
+ break;
+ case 3:
+ {
+ Lisp_Object table_p = XCHARSET_DECODING_TABLE (charset);
+ int plane;
+
+ for (plane = byte_min; plane < byte_max; plane++)
+ {
+ Lisp_Object table_r
+ = get_ccs_octet_table (table_p, charset, plane);
+ int row;
+
+ for (row = byte_min; row < byte_max; row++)
+ {
+ Lisp_Object table_c
+ = get_ccs_octet_table (table_r, charset, row);
+ int cell;
+
+ for (cell = byte_min; cell < byte_max; cell++)
+ {
+ Lisp_Object c = get_ccs_octet_table (table_c, charset,
+ cell);
+
+ if (CHARP (c))
+ {
+#ifdef HAVE_LIBCHISE
+ chise_ccs_set_decoded_char
+ (dt_ccs,
+ (plane << 16)
+ | (row << 8)
+ | cell, XCHAR (c));
+#else /* HAVE_LIBCHISE */
+ Fput_database (Fprin1_to_string
+ (make_int ((plane << 16)
+ | (row << 8)
+ | cell),
+ Qnil),
+ Fprin1_to_string (c, Qnil),
+ db, Qt);
+#endif /* not HAVE_LIBCHISE */
+ }
+ }
+ }
+ }
+ }
+ break;
+ default:
+ {
+ Lisp_Object table_g = XCHARSET_DECODING_TABLE (charset);
+ int group;
+
+ for (group = byte_min; group < byte_max; group++)
+ {
+ Lisp_Object table_p
+ = get_ccs_octet_table (table_g, charset, group);
+ int plane;
+
+ for (plane = byte_min; plane < byte_max; plane++)
+ {
+ Lisp_Object table_r
+ = get_ccs_octet_table (table_p, charset, plane);
+ int row;
+
+ for (row = byte_min; row < byte_max; row++)
+ {
+ Lisp_Object table_c
+ = get_ccs_octet_table (table_r, charset, row);
+ int cell;
+
+ for (cell = byte_min; cell < byte_max; cell++)
+ {
+ Lisp_Object c
+ = get_ccs_octet_table (table_c, charset, cell);
+
+ if (CHARP (c))
+ {
+#ifdef HAVE_LIBCHISE
+ chise_ccs_set_decoded_char
+ (dt_ccs,
+ ( group << 24)
+ | (plane << 16)
+ | (row << 8)
+ | cell, XCHAR (c));
+#else /* HAVE_LIBCHISE */
+ Fput_database (Fprin1_to_string
+ (make_int (( group << 24)
+ | (plane << 16)
+ | (row << 8)
+ | cell),
+ Qnil),
+ Fprin1_to_string (c, Qnil),
+ db, Qt);
+#endif /* not HAVE_LIBCHISE */
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+#ifdef HAVE_LIBCHISE
+ chise_ccs_sync (dt_ccs);
+ return Qnil;
+#else /* HAVE_LIBCHISE */
+ return Fclose_database (db);
+#endif /* not HAVE_LIBCHISE */
+}
+
+DEFUN ("reset-charset-mapping-table", Freset_charset_mapping_table, 1, 1, 0, /*
+Reset mapping-table of CCS with database file.
+*/
+ (ccs))
+{
+#ifdef HAVE_LIBCHISE
+ CHISE_CCS chise_ccs;
+#else
+ Lisp_Object db_file;
+#endif
+
+ ccs = Fget_charset (ccs);
+
+#ifdef HAVE_LIBCHISE
+ if ( open_chise_data_source_maybe () )
+ return -1;
+
+ chise_ccs = chise_ds_get_ccs (default_chise_data_source,
+ XSTRING_DATA (Fsymbol_name
+ (XCHARSET_NAME(ccs))));
+ if (chise_ccs == NULL)
+ return Qnil;
+#else
+ db_file = char_attribute_system_db_file (XCHARSET_NAME(ccs),
+ Qsystem_char_id, 0);
+#endif
+
+ if (
+#ifdef HAVE_LIBCHISE
+ chise_ccs_setup_db (chise_ccs, 0) == 0
+#else
+ !NILP (Ffile_exists_p (db_file))
+#endif
+ )
+ {
+ XCHARSET_DECODING_TABLE(ccs) = Qunloaded;
+ return Qt;
+ }
+ return Qnil;
+}
+
+Emchar
+load_char_decoding_entry_maybe (Lisp_Object ccs, int code_point)
+{
+#ifdef HAVE_LIBCHISE
+ CHISE_Char_ID char_id;
+
+ if ( open_chise_data_source_maybe () )
+ return -1;
+
+ char_id
+ = chise_ds_decode_char (default_chise_data_source,
+ XSTRING_DATA(Fsymbol_name (XCHARSET_NAME(ccs))),
+ code_point);
+#if 0
+ if (char_id >= 0)
+ decoding_table_put_char (ccs, code_point, make_char (char_id));
+ else
+ decoding_table_put_char (ccs, code_point, Qnil);
+#endif
+
+ /* chise_ccst_close (dt_ccs); */
+ return char_id;
+#else /* HAVE_LIBCHISE */
+ Lisp_Object db;
+ Lisp_Object db_file
+ = char_attribute_system_db_file (XCHARSET_NAME(ccs), Qsystem_char_id,
+ 0);
+
+ db = Fopen_database (db_file, Qnil, Qnil, build_string ("r"), Qnil);
+ if (!NILP (db))
+ {
+ Lisp_Object ret
+ = Fget_database (Fprin1_to_string (make_int (code_point), Qnil),
+ db, Qnil);
+ if (!NILP (ret))
+ {
+ ret = Fread (ret);
+ if (CHARP (ret))
+ {
+ decoding_table_put_char (ccs, code_point, ret);
+ Fclose_database (db);
+ return XCHAR (ret);
+ }
+ }
+ decoding_table_put_char (ccs, code_point, Qnil);
+ Fclose_database (db);
+ }
+ return -1;
+#endif /* not HAVE_LIBCHISE */
+}
+
+#ifdef HAVE_LIBCHISE
+DEFUN ("save-charset-properties", Fsave_charset_properties, 1, 1, 0, /*
+Save properties of CHARSET.
+*/
+ (charset))
+{
+ struct Lisp_Charset *cs;
+ CHISE_Property property;
+ Lisp_Object ccs;
+ unsigned char* feature_name;
+
+ ccs = Fget_charset (charset);
+ cs = XCHARSET (ccs);
+
+ if ( open_chise_data_source_maybe () )
+ return -1;
+
+ if ( SYMBOLP (charset) && !EQ (charset, XCHARSET_NAME (ccs)) )
+ {
+ property = chise_ds_get_property (default_chise_data_source,
+ "true-name");
+ feature_name = XSTRING_DATA (Fsymbol_name (charset));
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, XSTRING_DATA (Fprin1_to_string (CHARSET_NAME (cs),
+ Qnil)));
+ chise_property_sync (property);
+ }
+ charset = XCHARSET_NAME (ccs);
+ feature_name = XSTRING_DATA (Fsymbol_name (charset));
+
+ property = chise_ds_get_property (default_chise_data_source,
+ "description");
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, XSTRING_DATA (Fprin1_to_string
+ (CHARSET_DOC_STRING (cs), Qnil)));
+ chise_property_sync (property);
+
+ property = chise_ds_get_property (default_chise_data_source, "type");
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, "CCS");
+ chise_property_sync (property);
+
+ property = chise_ds_get_property (default_chise_data_source, "chars");
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, XSTRING_DATA (Fprin1_to_string (make_int
+ (CHARSET_CHARS (cs)),
+ Qnil)));
+ chise_property_sync (property);
+
+ property = chise_ds_get_property (default_chise_data_source, "dimension");
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, XSTRING_DATA (Fprin1_to_string (make_int
+ (CHARSET_DIMENSION (cs)),
+ Qnil)));
+ chise_property_sync (property);
+
+ if ( CHARSET_FINAL (cs) != 0 )
+ {
+ property = chise_ds_get_property (default_chise_data_source,
+ "final-byte");
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, XSTRING_DATA (Fprin1_to_string (make_int
+ (CHARSET_FINAL (cs)),
+ Qnil)));
+ chise_property_sync (property);
+ }
+
+ if ( !NILP (CHARSET_MOTHER (cs)) )
+ {
+ Lisp_Object mother = CHARSET_MOTHER (cs);
+
+ if ( CHARSETP (mother) )
+ mother = XCHARSET_NAME (mother);
+
+ property = chise_ds_get_property (default_chise_data_source,
+ "mother");
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, XSTRING_DATA (Fprin1_to_string (mother, Qnil)));
+ chise_property_sync (property);
+ }
+
+ if ( CHARSET_MAX_CODE (cs) != 0 )
+ {
+ char str[16];
+
+ property = chise_ds_get_property (default_chise_data_source,
+ "mother-code-min");
+ if ( CHARSET_MIN_CODE (cs) == 0 )
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, "0");
+ else
+ {
+ sprintf (str, "#x%X", CHARSET_MIN_CODE (cs));
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, str);
+ }
+ chise_property_sync (property);
+
+ property = chise_ds_get_property (default_chise_data_source,
+ "mother-code-max");
+ sprintf (str, "#x%X", CHARSET_MAX_CODE (cs));
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, str);
+ chise_property_sync (property);
+
+ property = chise_ds_get_property (default_chise_data_source,
+ "mother-code-offset");
+ if ( CHARSET_CODE_OFFSET (cs) == 0 )
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, "0");
+ else
+ {
+ sprintf (str, "#x%X", CHARSET_CODE_OFFSET (cs));
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, str);
+ }
+ chise_property_sync (property);
+
+ property = chise_ds_get_property (default_chise_data_source,
+ "mother-code-conversion");
+ if ( CHARSET_CONVERSION (cs) == CONVERSION_IDENTICAL )
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, "identical");
+ else
+ {
+ Lisp_Object sym = Qnil;
+
+ if ( CHARSET_CONVERSION (cs) == CONVERSION_94x60 )
+ sym = Q94x60;
+ else if ( CHARSET_CONVERSION (cs) == CONVERSION_94x94x60 )
+ sym = Q94x94x60;
+ else if ( CHARSET_CONVERSION (cs) == CONVERSION_BIG5_1 )
+ sym = Qbig5_1;
+ else if ( CHARSET_CONVERSION (cs) == CONVERSION_BIG5_2 )
+ sym = Qbig5_2;
+ if ( !NILP (sym) )
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, XSTRING_DATA (Fprin1_to_string (sym, Qnil)));
+ else
+ chise_feature_set_property_value
+ (chise_ds_get_feature (default_chise_data_source, feature_name),
+ property, "unknown");
+ }
+ chise_property_sync (property);
+ }
+ return Qnil;
+}
+#endif /* HAVE_LIBCHISE */
+
+#endif /* HAVE_CHISE */
+#endif /* UTF2000 */
+