X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fchartab.c;h=6e12d840e5598646ea12bf7ca98b41b210313e61;hb=15fd1e6e063e07e811ab9d9e4611682baa4df555;hp=865a38ccd5225b2a250c2da63cfc155775227a2c;hpb=ae83be1f7539c665df52de4097807a3616092d58;p=chise%2Fxemacs-chise.git diff --git a/src/chartab.c b/src/chartab.c index 865a38c..6e12d84 100644 --- a/src/chartab.c +++ b/src/chartab.c @@ -67,9 +67,6 @@ Lisp_Object Vword_combining_categories, Vword_separating_categories; #ifdef UTF2000 -static void -decode_char_table_range (Lisp_Object range, struct chartab_range *outrange); - #define BT_UINT8_MIN 0 #define BT_UINT8_MAX (UCHAR_MAX - 3) #define BT_UINT8_t (UCHAR_MAX - 2) @@ -193,12 +190,16 @@ uint8_byte_table_hash (Lisp_Object obj, int depth) return hash; } +static const struct lrecord_description uint8_byte_table_description[] = { + { XD_END } +}; + DEFINE_LRECORD_IMPLEMENTATION ("uint8-byte-table", uint8_byte_table, mark_uint8_byte_table, print_uint8_byte_table, 0, uint8_byte_table_equal, uint8_byte_table_hash, - 0 /* uint8_byte_table_description */, + uint8_byte_table_description, Lisp_Uint8_Byte_Table); static Lisp_Object @@ -254,7 +255,6 @@ uint8_byte_table_same_value_p (Lisp_Object obj) static int map_over_uint8_byte_table (Lisp_Uint8_Byte_Table *ct, Emchar ofs, int place, - Lisp_Object ccs, int (*fn) (struct chartab_range *range, Lisp_Object val, void *arg), void *arg) @@ -274,11 +274,8 @@ map_over_uint8_byte_table (Lisp_Uint8_Byte_Table *ct, Emchar ofs, int place, c1 = c + unit; for (; c < c1 && retval == 0; c++) { - if ( NILP (ccs) || charset_code_point (ccs, c) >= 0 ) - { - rainj.ch = c; - retval = (fn) (&rainj, UINT8_DECODE (ct->property[i]), arg); - } + rainj.ch = c; + retval = (fn) (&rainj, UINT8_DECODE (ct->property[i]), arg); } } else @@ -422,12 +419,16 @@ uint16_byte_table_hash (Lisp_Object obj, int depth) return hash; } +static const struct lrecord_description uint16_byte_table_description[] = { + { XD_END } +}; + DEFINE_LRECORD_IMPLEMENTATION ("uint16-byte-table", uint16_byte_table, mark_uint16_byte_table, print_uint16_byte_table, 0, uint16_byte_table_equal, uint16_byte_table_hash, - 0 /* uint16_byte_table_description */, + uint16_byte_table_description, Lisp_Uint16_Byte_Table); static Lisp_Object @@ -501,7 +502,6 @@ uint16_byte_table_same_value_p (Lisp_Object obj) static int map_over_uint16_byte_table (Lisp_Uint16_Byte_Table *ct, Emchar ofs, int place, - Lisp_Object ccs, int (*fn) (struct chartab_range *range, Lisp_Object val, void *arg), void *arg) @@ -521,12 +521,8 @@ map_over_uint16_byte_table (Lisp_Uint16_Byte_Table *ct, Emchar ofs, int place, c1 = c + unit; for (; c < c1 && retval == 0; c++) { - if ( NILP (ccs) || charset_code_point (ccs, c) >= 0 ) - { - rainj.ch = c; - retval = (fn) (&rainj, UINT16_DECODE (ct->property[i]), - arg); - } + rainj.ch = c; + retval = (fn) (&rainj, UINT16_DECODE (ct->property[i]), arg); } } else @@ -683,7 +679,6 @@ byte_table_same_value_p (Lisp_Object obj) static int map_over_byte_table (Lisp_Byte_Table *ct, Emchar ofs, int place, - Lisp_Object ccs, int (*fn) (struct chartab_range *range, Lisp_Object val, void *arg), void *arg) @@ -700,20 +695,20 @@ map_over_byte_table (Lisp_Byte_Table *ct, Emchar ofs, int place, { retval = map_over_uint8_byte_table (XUINT8_BYTE_TABLE(v), - c, place - 1, ccs, fn, arg); + c, place - 1, fn, arg); c += unit; } else if (UINT16_BYTE_TABLE_P (v)) { retval = map_over_uint16_byte_table (XUINT16_BYTE_TABLE(v), - c, place - 1, ccs, fn, arg); + c, place - 1, fn, arg); c += unit; } else if (BYTE_TABLE_P (v)) { retval = map_over_byte_table (XBYTE_TABLE(v), - c, place - 1, ccs, fn, arg); + c, place - 1, fn, arg); c += unit; } else if (!UNBOUNDP (v)) @@ -725,11 +720,8 @@ map_over_byte_table (Lisp_Byte_Table *ct, Emchar ofs, int place, for (; c < c1 && retval == 0; c++) { - if ( NILP (ccs) || charset_code_point (ccs, c) >= 0 ) - { - rainj.ch = c; - retval = (fn) (&rainj, v, arg); - } + rainj.ch = c; + retval = (fn) (&rainj, v, arg); } } else @@ -855,119 +847,6 @@ make_char_id_table (Lisp_Object initval) return obj; } -Lisp_Object -get_char_id_table (Lisp_Char_Table* cit, Emchar ch) -{ - Lisp_Object val = 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); - if (UNBOUNDP (val)) - return cit->default_value; - else - return val; -} - -void -put_char_id_table (Lisp_Char_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_DEFAULT: - cit->default_value = value; - break; - case CHARTAB_RANGE_CHARSET: - { - Emchar c; - Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (range.charset); - - if ( CHAR_TABLEP (encoding_table) ) - { - for (c = 0; c < 1 << 24; c++) - { - if ( INTP (get_char_id_table (XCHAR_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; - } -} - Lisp_Object Vcharacter_composition_table; Lisp_Object Vcharacter_variant_table; @@ -1831,7 +1710,32 @@ as CHAR-TABLE. The values will not themselves be copied. return obj; } -static void +INLINE_HEADER int XCHARSET_CELL_RANGE (Lisp_Object ccs); +INLINE_HEADER int +XCHARSET_CELL_RANGE (Lisp_Object ccs) +{ + switch (XCHARSET_CHARS (ccs)) + { + case 94: + return (33 << 8) | 126; + case 96: + return (32 << 8) | 127; +#ifdef UTF2000 + case 128: + return (0 << 8) | 127; + case 256: + return (0 << 8) | 255; +#endif + default: + abort (); + return 0; + } +} + +#ifndef UTF2000 +static +#endif +void decode_char_table_range (Lisp_Object range, struct chartab_range *outrange) { if (EQ (range, Qt)) @@ -1851,30 +1755,39 @@ decode_char_table_range (Lisp_Object range, struct chartab_range *outrange) { Lisp_Vector *vec = XVECTOR (range); Lisp_Object *elts = vector_data (vec); - if (vector_length (vec) != 2) - signal_simple_error ("Length of charset row vector must be 2", - range); + int cell_min, cell_max; + outrange->type = CHARTAB_RANGE_ROW; outrange->charset = Fget_charset (elts[0]); CHECK_INT (elts[1]); outrange->row = XINT (elts[1]); - if (XCHARSET_DIMENSION (outrange->charset) >= 2) + if (XCHARSET_DIMENSION (outrange->charset) < 2) + signal_simple_error ("Charset in row vector must be multi-byte", + outrange->charset); + else { - switch (XCHARSET_CHARS (outrange->charset)) - { - case 94: - check_int_range (outrange->row, 33, 126); - break; - case 96: - check_int_range (outrange->row, 32, 127); - break; - default: - abort (); - } + int ret = XCHARSET_CELL_RANGE (outrange->charset); + + cell_min = ret >> 8; + cell_max = ret & 0xFF; } + if (XCHARSET_DIMENSION (outrange->charset) == 2) + check_int_range (outrange->row, cell_min, cell_max); +#ifdef UTF2000 + else if (XCHARSET_DIMENSION (outrange->charset) == 3) + { + check_int_range (outrange->row >> 8 , cell_min, cell_max); + check_int_range (outrange->row & 0xFF, cell_min, cell_max); + } + else if (XCHARSET_DIMENSION (outrange->charset) == 4) + { + check_int_range ( outrange->row >> 16 , cell_min, cell_max); + check_int_range ((outrange->row >> 8) & 0xFF, cell_min, cell_max); + check_int_range ( outrange->row & 0xFF, cell_min, cell_max); + } +#endif else - signal_simple_error ("Charset in row vector must be multi-byte", - outrange->charset); + abort (); } else { @@ -1930,18 +1843,7 @@ Lisp_Object get_char_table (Emchar ch, Lisp_Char_Table *ct) { #ifdef UTF2000 - 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; + return get_char_id_table (ct, ch); #elif defined(MULE) { Lisp_Object charset; @@ -2241,7 +2143,7 @@ put_char_table (Lisp_Char_Table *ct, struct chartab_range *range, { for (c = 0; c < 1 << 24; c++) { - if ( charset_code_point (range->charset, c) >= 0 ) + if ( charset_code_point (range->charset, c, 0) >= 0 ) put_char_id_table_0 (ct, c, val); } } @@ -2272,51 +2174,14 @@ put_char_table (Lisp_Char_Table *ct, struct chartab_range *range, { int cell_min, cell_max, i; - /* printf ("put-char-table: range = charset-row: %d, 0x%x\n", - XCHARSET_LEADING_BYTE (range->charset), range->row); */ - 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 (); - + i = XCHARSET_CELL_RANGE (range->charset); + cell_min = i >> 8; + cell_max = i & 0xFF; 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 ) + + if ( charset_code_point (range->charset, ch, 0) >= 0 ) put_char_id_table_0 (ct, ch, val); } } @@ -2639,14 +2504,14 @@ map_char_table (Lisp_Char_Table *ct, return retval; } if (UINT8_BYTE_TABLE_P (ct->table)) - return map_over_uint8_byte_table (XUINT8_BYTE_TABLE(ct->table), 0, 3, - Qnil, fn, arg); + return map_over_uint8_byte_table (XUINT8_BYTE_TABLE(ct->table), + 0, 3, fn, arg); else if (UINT16_BYTE_TABLE_P (ct->table)) - return map_over_uint16_byte_table (XUINT16_BYTE_TABLE(ct->table), 0, 3, - Qnil, fn, arg); + return map_over_uint16_byte_table (XUINT16_BYTE_TABLE(ct->table), + 0, 3, fn, arg); else if (BYTE_TABLE_P (ct->table)) - return map_over_byte_table (XBYTE_TABLE(ct->table), 0, 3, - Qnil, fn, arg); + return map_over_byte_table (XBYTE_TABLE(ct->table), + 0, 3, fn, arg); else if (!UNBOUNDP (ct->table)) #if 0 { @@ -2738,51 +2603,15 @@ map_char_table (Lisp_Char_Table *ct, int retval; struct chartab_range rainj; - 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 (); - + i = XCHARSET_CELL_RANGE (range->charset); + cell_min = i >> 8; + cell_max = i & 0xFF; rainj.type = CHARTAB_RANGE_CHAR; for (retval =0, i = cell_min; i <= cell_max && retval == 0; i++) { 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 @@ -3015,41 +2844,20 @@ Return the alist of attributes of CHARACTER. */ (character)) { + struct gcpro gcpro1; + struct char_attribute_alist_closure char_attribute_alist_closure; Lisp_Object alist = Qnil; - int i; CHECK_CHAR (character); - { - struct gcpro gcpro1; - struct char_attribute_alist_closure char_attribute_alist_closure; - - GCPRO1 (alist); - char_attribute_alist_closure.char_id = XCHAR (character); - char_attribute_alist_closure.char_attribute_alist = &alist; - elisp_maphash (add_char_attribute_alist_mapper, - Vchar_attribute_hash_table, - &char_attribute_alist_closure); - UNGCPRO; - } - - for (i = 0; i < countof (chlook->charset_by_leading_byte); i++) - { - Lisp_Object ccs = chlook->charset_by_leading_byte[i]; - if (!NILP (ccs)) - { - Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (ccs); - Lisp_Object cpos; + GCPRO1 (alist); + char_attribute_alist_closure.char_id = XCHAR (character); + char_attribute_alist_closure.char_attribute_alist = &alist; + elisp_maphash (add_char_attribute_alist_mapper, + Vchar_attribute_hash_table, + &char_attribute_alist_closure); + UNGCPRO; - if ( CHAR_TABLEP (encoding_table) - && INTP (cpos - = get_char_id_table (XCHAR_TABLE(encoding_table), - XCHAR (character))) ) - { - alist = Fcons (Fcons (ccs, cpos), alist); - } - } - } return alist; } @@ -3059,29 +2867,21 @@ Return DEFAULT-VALUE if the value is not exist. */ (character, attribute, default_value)) { - Lisp_Object ccs; + Lisp_Object table; CHECK_CHAR (character); - if (!NILP (ccs = Ffind_charset (attribute))) - { - Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (ccs); - if (CHAR_TABLEP (encoding_table)) - return get_char_id_table (XCHAR_TABLE(encoding_table), - XCHAR (character)); - } - else + if (CHARSETP (attribute)) + attribute = XCHARSET_NAME (attribute); + + table = Fgethash (attribute, Vchar_attribute_hash_table, + Qunbound); + if (!UNBOUNDP (table)) { - Lisp_Object table = Fgethash (attribute, - Vchar_attribute_hash_table, - Qunbound); - if (!UNBOUNDP (table)) - { - Lisp_Object ret = get_char_id_table (XCHAR_TABLE(table), - XCHAR (character)); - if (!UNBOUNDP (ret)) - return ret; - } + Lisp_Object ret = get_char_id_table (XCHAR_TABLE(table), + XCHAR (character)); + if (!UNBOUNDP (ret)) + return ret; } return default_value; } @@ -3091,13 +2891,12 @@ Store CHARACTER's ATTRIBUTE with VALUE. */ (character, attribute, value)) { - Lisp_Object ccs; + Lisp_Object ccs = Ffind_charset (attribute); - ccs = Ffind_charset (attribute); if (!NILP (ccs)) { CHECK_CHAR (character); - return put_char_ccs_code_point (character, ccs, value); + value = put_char_ccs_code_point (character, ccs, value); } else if (EQ (attribute, Q_decomposition)) { @@ -3281,9 +3080,6 @@ the entire table. return slarg.retval; } -EXFUN (Fmake_char, 3); -EXFUN (Fdecode_char, 2); - DEFUN ("define-char", Fdefine_char, 1, 1, 0, /* Store character's ATTRIBUTES. */ @@ -3304,13 +3100,14 @@ Store character's ATTRIBUTES. signal_simple_error ("Invalid argument", attributes); if (!NILP (ccs = Ffind_charset (Fcar (cell))) && ((XCHARSET_FINAL (ccs) != 0) || - (XCHARSET_UCS_MAX (ccs) > 0)) ) + (XCHARSET_MAX_CODE (ccs) > 0) || + (EQ (ccs, Vcharset_chinese_big5))) ) { cell = Fcdr (cell); if (CONSP (cell)) character = Fmake_char (ccs, Fcar (cell), Fcar (Fcdr (cell))); else - character = Fdecode_char (ccs, cell); + character = Fdecode_char (ccs, cell, Qnil); if (!NILP (character)) goto setup_attributes; } @@ -3369,7 +3166,7 @@ Retrieve the character of the given ATTRIBUTES. if (CONSP (cell)) return Fmake_char (ccs, Fcar (cell), Fcar (Fcdr (cell))); else - return Fdecode_char (ccs, cell); + return Fdecode_char (ccs, cell, Qnil); } rest = Fcdr (rest); } @@ -3531,7 +3328,7 @@ check_category_table (Lisp_Object object, Lisp_Object default_) int check_category_char (Emchar ch, Lisp_Object table, - unsigned int designator, unsigned int not) + unsigned int designator, unsigned int not_p) { REGISTER Lisp_Object temp; Lisp_Char_Table *ctbl; @@ -3542,10 +3339,10 @@ check_category_char (Emchar ch, Lisp_Object table, ctbl = XCHAR_TABLE (table); temp = get_char_table (ch, ctbl); if (NILP (temp)) - return not; + return not_p; designator -= ' '; - return bit_vector_bit (XBIT_VECTOR (temp), designator) ? !not : not; + return bit_vector_bit (XBIT_VECTOR (temp), designator) ? !not_p : not_p; } DEFUN ("check-category-at", Fcheck_category_at, 2, 4, 0, /*