+
+DEFUN ("save-charset-mapping-table", Fsave_charset_mapping_table, 1, 1, 0, /*
+Save mapping-table of CHARSET.
+*/
+ (charset))
+{
+#ifdef HAVE_DATABASE
+ struct Lisp_Charset *cs;
+ int byte_min, byte_max;
+ Lisp_Object db;
+ Lisp_Object db_file;
+
+ charset = Fget_charset (charset);
+ cs = XCHARSET (charset);
+
+ 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);
+
+ 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))
+ Fput_database (Fprin1_to_string (make_int (cell), Qnil),
+ Fprin1_to_string (c, Qnil),
+ db, Qt);
+ }
+ }
+ 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))
+ Fput_database (Fprin1_to_string (make_int ((row << 8)
+ | cell),
+ Qnil),
+ Fprin1_to_string (c, Qnil),
+ db, Qt);
+ }
+ }
+ }
+ 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))
+ Fput_database (Fprin1_to_string (make_int ((plane << 16)
+ | (row << 8)
+ | cell),
+ Qnil),
+ Fprin1_to_string (c, Qnil),
+ db, Qt);
+ }
+ }
+ }
+ }
+ 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))
+ Fput_database (Fprin1_to_string
+ (make_int (( group << 24)
+ | (plane << 16)
+ | (row << 8)
+ | cell),
+ Qnil),
+ Fprin1_to_string (c, Qnil),
+ db, Qt);
+ }
+ }
+ }
+ }
+ }
+ }
+ return Fclose_database (db);
+#else
+ return Qnil;