- table = make_uint16_byte_table (UINT16_ENCODE (table));
- XUINT16_BYTE_TABLE(table)->property[idx] = UINT16_ENCODE (value);
- }
- else
- {
- table = make_byte_table (table);
- XBYTE_TABLE(table)->property[idx] = value;
- }
- }
- return table;
-}
-
-static Lisp_Object
-mark_char_id_table (Lisp_Object obj)
-{
- Lisp_Char_ID_Table *cte = XCHAR_ID_TABLE (obj);
-
- return cte->table;
-}
-
-static void
-print_char_id_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
-{
- Lisp_Object table = XCHAR_ID_TABLE (obj)->table;
- int i;
- struct gcpro gcpro1, gcpro2;
- GCPRO2 (obj, printcharfun);
-
- write_c_string ("#<char-id-table ", printcharfun);
- for (i = 0; i < 256; i++)
- {
- Lisp_Object elt = get_byte_table (table, i);
- if (i != 0) write_c_string ("\n ", printcharfun);
- if (EQ (elt, Qunbound))
- write_c_string ("void", printcharfun);
- else
- print_internal (elt, printcharfun, escapeflag);
- }
- UNGCPRO;
- write_c_string (">", printcharfun);
-}
-
-static int
-char_id_table_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
-{
- Lisp_Object table1 = XCHAR_ID_TABLE (obj1)->table;
- Lisp_Object table2 = XCHAR_ID_TABLE (obj2)->table;
- int i;
-
- for (i = 0; i < 256; i++)
- {
- if (!internal_equal (get_byte_table (table1, i),
- get_byte_table (table2, i), 0))
- return 0;
- }
- return -1;
-}
-
-static unsigned long
-char_id_table_hash (Lisp_Object obj, int depth)
-{
- Lisp_Char_ID_Table *cte = XCHAR_ID_TABLE (obj);
-
- return char_id_table_hash (cte->table, depth + 1);
-}
-
-static const struct lrecord_description char_id_table_description[] = {
- { XD_LISP_OBJECT, offsetof(Lisp_Char_ID_Table, table) },
- { XD_END }
-};
-
-DEFINE_LRECORD_IMPLEMENTATION ("char-id-table", char_id_table,
- mark_char_id_table,
- print_char_id_table,
- 0, char_id_table_equal,
- char_id_table_hash,
- char_id_table_description,
- Lisp_Char_ID_Table);
-
-Lisp_Object
-make_char_id_table (Lisp_Object initval)
-{
- Lisp_Object obj;
- Lisp_Char_ID_Table *cte;
-
- cte = alloc_lcrecord_type (Lisp_Char_ID_Table, &lrecord_char_id_table);
-
- cte->table = make_byte_table (initval);
-
- XSETCHAR_ID_TABLE (obj, cte);
- return obj;
-}
-
-
-Lisp_Object
-get_char_id_table (Lisp_Char_ID_Table* cit, Emchar ch)
-{
- unsigned int code = ch;
-
- return get_byte_table (get_byte_table
- (get_byte_table
- (get_byte_table
- (cit->table,
- (unsigned char)(code >> 24)),
- (unsigned char) (code >> 16)),
- (unsigned char) (code >> 8)),
- (unsigned char) code);
-}
-
-INLINE_HEADER void
-put_char_id_table_0 (Lisp_Char_ID_Table* cit, Emchar code, Lisp_Object value);
-INLINE_HEADER void
-put_char_id_table_0 (Lisp_Char_ID_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);
-}
-
-void
-put_char_id_table (Lisp_Char_ID_Table* cit,
- Lisp_Object character, Lisp_Object value)
-{
- struct chartab_range range;
-
- decode_char_table_range (character, &range);
- switch (range.type)
- {
- case CHARTAB_RANGE_ALL:
- cit->table = value;
- break;
- case CHARTAB_RANGE_CHARSET:
- {
- Emchar c;
- Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (range.charset);
-
- if ( CHAR_ID_TABLE_P (encoding_table) )
- {
- for (c = 0; c < 1 << 24; c++)
- {
- if ( INTP (get_char_id_table (XCHAR_ID_TABLE(encoding_table),
- c)) )
- put_char_id_table_0 (cit, c, value);
- }
- }
- else
- {
- for (c = 0; c < 1 << 24; c++)
- {
- if ( charset_code_point (range.charset, c) >= 0 )
- put_char_id_table_0 (cit, c, value);
- }
- }
- }
- break;
- case CHARTAB_RANGE_ROW:
- {
- int cell_min, cell_max, i;
-
- if (XCHARSET_DIMENSION (range.charset) < 2)
- signal_simple_error ("Charset in row vector must be multi-byte",
- range.charset);
- else
- {
- switch (XCHARSET_CHARS (range.charset))
- {
- case 94:
- cell_min = 33; cell_max = 126;
- break;
- case 96:
- cell_min = 32; cell_max = 127;
- break;
- case 128:
- cell_min = 0; cell_max = 127;
- break;
- case 256:
- cell_min = 0; cell_max = 255;
- break;
- default:
- abort ();
- }
- }
- if (XCHARSET_DIMENSION (range.charset) == 2)
- check_int_range (range.row, cell_min, cell_max);
- else if (XCHARSET_DIMENSION (range.charset) == 3)
- {
- check_int_range (range.row >> 8 , cell_min, cell_max);
- check_int_range (range.row & 0xFF, cell_min, cell_max);
- }
- else if (XCHARSET_DIMENSION (range.charset) == 4)
- {
- check_int_range ( range.row >> 16 , cell_min, cell_max);
- check_int_range ((range.row >> 8) & 0xFF, cell_min, cell_max);
- check_int_range ( range.row & 0xFF, cell_min, cell_max);
- }
- else
- abort ();
-
- for (i = cell_min; i <= cell_max; i++)
- {
- Emchar ch = DECODE_CHAR (range.charset, (range.row << 8) | i);
- if ( charset_code_point (range.charset, ch) >= 0 )
- put_char_id_table_0 (cit, ch, value);
- }
- }
- break;
- case CHARTAB_RANGE_CHAR:
- put_char_id_table_0 (cit, range.ch, value);
- break;
- }
-}
-
-/* Map FN (with client data ARG) in char table CT.
- Mapping stops the first time FN returns non-zero, and that value
- becomes the return value of map_char_id_table(). */
-int
-map_char_id_table (Lisp_Char_ID_Table *ct,
- struct chartab_range *range,
- int (*fn) (struct chartab_range *range,
- Lisp_Object val, void *arg),
- void *arg)
-{
- Lisp_Object v = ct->table;
-
- switch (range->type)
- {
- case CHARTAB_RANGE_ALL:
- if (UINT8_BYTE_TABLE_P (v))
- return map_over_uint8_byte_table (XUINT8_BYTE_TABLE(v), 0, 3,
- Qnil, fn, arg);
- else if (UINT16_BYTE_TABLE_P (v))
- return map_over_uint16_byte_table (XUINT16_BYTE_TABLE(v), 0, 3,
- Qnil, fn, arg);
- else if (BYTE_TABLE_P (v))
- return map_over_byte_table (XBYTE_TABLE(v), 0, 3, Qnil, fn, arg);
- else if (!UNBOUNDP (v))
- {
- struct chartab_range rainj;
- int unit = 1 << 24;
- Emchar c = 0;
- Emchar c1 = c + unit;
- int retval;
-
- rainj.type = CHARTAB_RANGE_CHAR;
-
- for (retval = 0; c < c1 && retval == 0; c++)
- {
- rainj.ch = c;
- retval = (fn) (&rainj, v, arg);
- }
- }
- return 0;
- case CHARTAB_RANGE_CHARSET:
- if (UINT8_BYTE_TABLE_P (v))
- return map_over_uint8_byte_table (XUINT8_BYTE_TABLE(v), 0, 3,
- range->charset, fn, arg);
- else if (UINT16_BYTE_TABLE_P (v))
- return map_over_uint16_byte_table (XUINT16_BYTE_TABLE(v), 0, 3,
- range->charset, fn, arg);
- else if (BYTE_TABLE_P (v))
- return map_over_byte_table (XBYTE_TABLE(v), 0, 3,
- range->charset, fn, arg);
- else if (!UNBOUNDP (v))