- write_c_string (" ", printcharfun);
- print_internal (make_char (first), printcharfun, 0);
- write_c_string (" ", printcharfun);
- }
- print_internal (val, printcharfun, 1);
-}
-#endif
-
-#if defined(MULE)&&!defined(UTF2000)
-
-static void
-print_chartab_charset_row (Lisp_Object charset,
- int row,
- Lisp_Char_Table_Entry *cte,
- Lisp_Object printcharfun)
-{
- int i;
- Lisp_Object cat = Qunbound;
- int first = -1;
-
- for (i = 32; i < 128; i++)
- {
- Lisp_Object pam = cte->level2[i - 32];
-
- if (first == -1)
- {
- first = i;
- cat = pam;
- continue;
- }
-
- if (!EQ (cat, pam))
- {
- if (row == -1)
- print_chartab_range (MAKE_CHAR (charset, first, 0),
- MAKE_CHAR (charset, i - 1, 0),
- cat, printcharfun);
- else
- print_chartab_range (MAKE_CHAR (charset, row, first),
- MAKE_CHAR (charset, row, i - 1),
- cat, printcharfun);
- first = -1;
- i--;
- }
- }
-
- if (first != -1)
- {
- if (row == -1)
- print_chartab_range (MAKE_CHAR (charset, first, 0),
- MAKE_CHAR (charset, i - 1, 0),
- cat, printcharfun);
- else
- print_chartab_range (MAKE_CHAR (charset, row, first),
- MAKE_CHAR (charset, row, i - 1),
- cat, printcharfun);
- }
-}
-
-static void
-print_chartab_two_byte_charset (Lisp_Object charset,
- Lisp_Char_Table_Entry *cte,
- Lisp_Object printcharfun)
-{
- int i;
-
- for (i = 32; i < 128; i++)
- {
- Lisp_Object jen = cte->level2[i - 32];
-
- if (!CHAR_TABLE_ENTRYP (jen))
- {
- char buf[100];
-
- write_c_string (" [", printcharfun);
- print_internal (XCHARSET_NAME (charset), printcharfun, 0);
- sprintf (buf, " %d] ", i);
- write_c_string (buf, printcharfun);
- print_internal (jen, printcharfun, 0);
- }
- else
- print_chartab_charset_row (charset, i, XCHAR_TABLE_ENTRY (jen),
- printcharfun);
- }
-}
-
-#endif /* MULE */
-
-static void
-print_char_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
-{
- Lisp_Char_Table *ct = XCHAR_TABLE (obj);
-#ifdef UTF2000
- int i;
- struct gcpro gcpro1, gcpro2;
- GCPRO2 (obj, printcharfun);
-
- write_c_string ("#s(char-table ", printcharfun);
- write_c_string (" ", printcharfun);
- write_c_string (string_data
- (symbol_name
- (XSYMBOL (char_table_type_to_symbol (ct->type)))),
- printcharfun);
- write_c_string ("\n ", printcharfun);
- print_internal (ct->default_value, printcharfun, escapeflag);
- for (i = 0; i < 256; i++)
- {
- Lisp_Object elt = get_byte_table (ct->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;
-#else /* non UTF2000 */
- char buf[200];
-
- sprintf (buf, "#s(char-table type %s data (",
- string_data (symbol_name (XSYMBOL
- (char_table_type_to_symbol (ct->type)))));
- write_c_string (buf, printcharfun);
-
- /* Now write out the ASCII/Control-1 stuff. */
- {
- int i;
- int first = -1;
- Lisp_Object val = Qunbound;
-
- for (i = 0; i < NUM_ASCII_CHARS; i++)
- {
- if (first == -1)
- {
- first = i;
- val = ct->ascii[i];
- continue;
- }
-
- if (!EQ (ct->ascii[i], val))
- {
- print_chartab_range (first, i - 1, val, printcharfun);
- first = -1;
- i--;
- }
- }
-
- if (first != -1)
- print_chartab_range (first, i - 1, val, printcharfun);
- }
-
-#ifdef MULE
- {
- Charset_ID i;
-
- for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
- i++)
- {
- Lisp_Object ann = ct->level1[i - MIN_LEADING_BYTE];
- Lisp_Object charset = CHARSET_BY_LEADING_BYTE (i);
-
- if (!CHARSETP (charset) || i == LEADING_BYTE_ASCII
- || i == LEADING_BYTE_CONTROL_1)
- continue;
- if (!CHAR_TABLE_ENTRYP (ann))
- {
- write_c_string (" ", printcharfun);
- print_internal (XCHARSET_NAME (charset),
- printcharfun, 0);
- write_c_string (" ", printcharfun);
- print_internal (ann, printcharfun, 0);
- }
- else
- {
- Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (ann);
- if (XCHARSET_DIMENSION (charset) == 1)
- print_chartab_charset_row (charset, -1, cte, printcharfun);
- else
- print_chartab_two_byte_charset (charset, cte, printcharfun);
- }
- }
- }
-#endif /* MULE */
-#endif /* non UTF2000 */
-
- write_c_string ("))", printcharfun);
-}
-
-static int
-char_table_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
-{
- Lisp_Char_Table *ct1 = XCHAR_TABLE (obj1);
- Lisp_Char_Table *ct2 = XCHAR_TABLE (obj2);
- int i;
-
- if (CHAR_TABLE_TYPE (ct1) != CHAR_TABLE_TYPE (ct2))
- return 0;
-
-#ifdef UTF2000
- for (i = 0; i < 256; i++)
- {
- if (!internal_equal (get_byte_table (ct1->table, i),
- get_byte_table (ct2->table, i), 0))
- return 0;
- }
-#else
- for (i = 0; i < NUM_ASCII_CHARS; i++)
- if (!internal_equal (ct1->ascii[i], ct2->ascii[i], depth + 1))
- return 0;
-
-#ifdef MULE
- for (i = 0; i < NUM_LEADING_BYTES; i++)
- if (!internal_equal (ct1->level1[i], ct2->level1[i], depth + 1))
- return 0;
-#endif /* MULE */
-#endif /* non UTF2000 */
-
- return 1;
-}
-
-static unsigned long
-char_table_hash (Lisp_Object obj, int depth)
-{
- Lisp_Char_Table *ct = XCHAR_TABLE (obj);
-#ifdef UTF2000
- return byte_table_hash (ct->table, depth + 1);
-#else
- unsigned long hashval = internal_array_hash (ct->ascii, NUM_ASCII_CHARS,
- depth);
-#ifdef MULE
- hashval = HASH2 (hashval,
- internal_array_hash (ct->level1, NUM_LEADING_BYTES, depth));
-#endif /* MULE */
- return hashval;
-#endif
-}
-
-static const struct lrecord_description char_table_description[] = {
-#ifdef UTF2000
- { XD_LISP_OBJECT, offsetof(Lisp_Char_Table, table) },
- { XD_LISP_OBJECT, offsetof(Lisp_Char_Table, default_value) },
- { XD_LISP_OBJECT, offsetof(Lisp_Char_Table, name) },
-#ifndef HAVE_LIBCHISE
- { XD_LISP_OBJECT, offsetof(Lisp_Char_Table, db) },
-#endif
-#else
- { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Char_Table, ascii), NUM_ASCII_CHARS },
-#ifdef MULE
- { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Char_Table, level1), NUM_LEADING_BYTES },
-#endif
-#endif
-#ifndef UTF2000
- { XD_LISP_OBJECT, offsetof (Lisp_Char_Table, mirror_table) },
-#endif
- { XD_LO_LINK, offsetof (Lisp_Char_Table, next_table) },
- { XD_END }
-};
-
-DEFINE_LRECORD_IMPLEMENTATION ("char-table", char_table,
- mark_char_table, print_char_table, 0,
- char_table_equal, char_table_hash,
- char_table_description,
- Lisp_Char_Table);
-
-DEFUN ("char-table-p", Fchar_table_p, 1, 1, 0, /*
-Return non-nil if OBJECT is a char table.
-
-A char table is a table that maps characters (or ranges of characters)
-to values. Char tables are specialized for characters, only allowing
-particular sorts of ranges to be assigned values. Although this
-loses in generality, it makes for extremely fast (constant-time)
-lookups, and thus is feasible for applications that do an extremely
-large number of lookups (e.g. scanning a buffer for a character in
-a particular syntax, where a lookup in the syntax table must occur
-once per character).
-
-When Mule support exists, the types of ranges that can be assigned
-values are
-
--- all characters
--- an entire charset
--- a single row in a two-octet charset
--- a single character
-
-When Mule support is not present, the types of ranges that can be
-assigned values are
-
--- all characters
--- a single character
-
-To create a char table, use `make-char-table'.
-To modify a char table, use `put-char-table' or `remove-char-table'.
-To retrieve the value for a particular character, use `get-char-table'.
-See also `map-char-table', `clear-char-table', `copy-char-table',
-`valid-char-table-type-p', `char-table-type-list',
-`valid-char-table-value-p', and `check-char-table-value'.
-*/
- (object))
-{
- return CHAR_TABLEP (object) ? Qt : Qnil;
-}
-
-DEFUN ("char-table-type-list", Fchar_table_type_list, 0, 0, 0, /*
-Return a list of the recognized char table types.
-See `valid-char-table-type-p'.
-*/
- ())
-{
-#ifdef MULE
- return list5 (Qchar, Qcategory, Qdisplay, Qgeneric, Qsyntax);
-#else
- return list4 (Qchar, Qdisplay, Qgeneric, Qsyntax);
-#endif
-}
-
-DEFUN ("valid-char-table-type-p", Fvalid_char_table_type_p, 1, 1, 0, /*
-Return t if TYPE if a recognized char table type.
-
-Each char table type is used for a different purpose and allows different
-sorts of values. The different char table types are
-
-`category'
- Used for category tables, which specify the regexp categories
- that a character is in. The valid values are nil or a
- bit vector of 95 elements. Higher-level Lisp functions are
- provided for working with category tables. Currently categories
- and category tables only exist when Mule support is present.
-`char'
- A generalized char table, for mapping from one character to
- another. Used for case tables, syntax matching tables,
- `keyboard-translate-table', etc. The valid values are characters.
-`generic'
- An even more generalized char table, for mapping from a
- character to anything.
-`display'
- Used for display tables, which specify how a particular character
- is to appear when displayed. #### Not yet implemented.
-`syntax'
- Used for syntax tables, which specify the syntax of a particular
- character. Higher-level Lisp functions are provided for
- working with syntax tables. The valid values are integers.
-
-*/
- (type))
-{
- return (EQ (type, Qchar) ||
-#ifdef MULE
- EQ (type, Qcategory) ||
-#endif
- EQ (type, Qdisplay) ||
- EQ (type, Qgeneric) ||
- EQ (type, Qsyntax)) ? Qt : Qnil;
-}
-
-DEFUN ("char-table-type", Fchar_table_type, 1, 1, 0, /*
-Return the type of CHAR-TABLE.
-See `valid-char-table-type-p'.
-*/
- (char_table))
-{
- CHECK_CHAR_TABLE (char_table);
- return char_table_type_to_symbol (XCHAR_TABLE (char_table)->type);
-}
-
-void
-fill_char_table (Lisp_Char_Table *ct, Lisp_Object value)
-{
-#ifdef UTF2000
- ct->table = Qunbound;
- ct->default_value = value;
- ct->unloaded = 0;
-#else
- int i;
-
- for (i = 0; i < NUM_ASCII_CHARS; i++)
- ct->ascii[i] = value;
-#ifdef MULE
- for (i = 0; i < NUM_LEADING_BYTES; i++)
- ct->level1[i] = value;
-#endif /* MULE */
-#endif
-
-#ifndef UTF2000
- if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
- update_syntax_table (ct);
-#endif
-}
-
-DEFUN ("reset-char-table", Freset_char_table, 1, 1, 0, /*
-Reset CHAR-TABLE to its default state.
-*/
- (char_table))
-{
- Lisp_Char_Table *ct;
-
- CHECK_CHAR_TABLE (char_table);
- ct = XCHAR_TABLE (char_table);
-
- switch (ct->type)
- {
- case CHAR_TABLE_TYPE_CHAR:
- fill_char_table (ct, make_char (0));
- break;
- case CHAR_TABLE_TYPE_DISPLAY:
- case CHAR_TABLE_TYPE_GENERIC:
-#ifdef MULE
- case CHAR_TABLE_TYPE_CATEGORY:
-#endif /* MULE */
- fill_char_table (ct, Qnil);
- break;
-
- case CHAR_TABLE_TYPE_SYNTAX:
- fill_char_table (ct, make_int (Sinherit));
- break;
-
- default:
- ABORT ();
- }
-
- return Qnil;
-}
-
-DEFUN ("make-char-table", Fmake_char_table, 1, 1, 0, /*
-Return a new, empty char table of type TYPE.
-Currently recognized types are 'char, 'category, 'display, 'generic,
-and 'syntax. See `valid-char-table-type-p'.
-*/
- (type))
-{
- Lisp_Char_Table *ct;
- Lisp_Object obj;
- enum char_table_type ty = symbol_to_char_table_type (type);
-
- ct = alloc_lcrecord_type (Lisp_Char_Table, &lrecord_char_table);
- ct->type = ty;
-#ifndef UTF2000
- if (ty == CHAR_TABLE_TYPE_SYNTAX)
- {
- ct->mirror_table = Fmake_char_table (Qgeneric);
- fill_char_table (XCHAR_TABLE (ct->mirror_table),
- make_int (Spunct));
- }
- else
- ct->mirror_table = Qnil;
-#else
- ct->name = Qnil;
-#ifndef HAVE_LIBCHISE
- ct->db = Qnil;
-#endif
-#endif
- ct->next_table = Qnil;
- XSETCHAR_TABLE (obj, ct);
- if (ty == CHAR_TABLE_TYPE_SYNTAX)
- {
- ct->next_table = Vall_syntax_tables;
- Vall_syntax_tables = obj;
- }
- Freset_char_table (obj);
- return obj;
-}
-
-#if defined(MULE)&&!defined(UTF2000)
-
-static Lisp_Object
-make_char_table_entry (Lisp_Object initval)
-{
- Lisp_Object obj;
- int i;
- Lisp_Char_Table_Entry *cte =
- alloc_lcrecord_type (Lisp_Char_Table_Entry, &lrecord_char_table_entry);
-
- for (i = 0; i < 96; i++)
- cte->level2[i] = initval;
-
- XSETCHAR_TABLE_ENTRY (obj, cte);
- return obj;
-}
-
-static Lisp_Object
-copy_char_table_entry (Lisp_Object entry)
-{
- Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (entry);
- Lisp_Object obj;
- int i;
- Lisp_Char_Table_Entry *ctenew =
- alloc_lcrecord_type (Lisp_Char_Table_Entry, &lrecord_char_table_entry);
-
- for (i = 0; i < 96; i++)
- {
- Lisp_Object new = cte->level2[i];
- if (CHAR_TABLE_ENTRYP (new))
- ctenew->level2[i] = copy_char_table_entry (new);
- else
- ctenew->level2[i] = new;
- }
-
- XSETCHAR_TABLE_ENTRY (obj, ctenew);
- return obj;
-}
-
-#endif /* MULE */
-
-DEFUN ("copy-char-table", Fcopy_char_table, 1, 1, 0, /*
-Return a new char table which is a copy of CHAR-TABLE.
-It will contain the same values for the same characters and ranges
-as CHAR-TABLE. The values will not themselves be copied.
-*/
- (char_table))
-{
- Lisp_Char_Table *ct, *ctnew;
- Lisp_Object obj;
-#ifndef UTF2000
- int i;
-#endif
-
- CHECK_CHAR_TABLE (char_table);
- ct = XCHAR_TABLE (char_table);
- ctnew = alloc_lcrecord_type (Lisp_Char_Table, &lrecord_char_table);
- ctnew->type = ct->type;
-#ifdef UTF2000
- ctnew->default_value = ct->default_value;
- /* [tomo:2002-01-21] Perhaps this code seems wrong */
- ctnew->name = ct->name;
-#ifndef HAVE_LIBCHISE
- ctnew->db = ct->db;
-#endif
-
- if (UINT8_BYTE_TABLE_P (ct->table))
- {
- ctnew->table = copy_uint8_byte_table (ct->table);
- }
- else if (UINT16_BYTE_TABLE_P (ct->table))
- {
- ctnew->table = copy_uint16_byte_table (ct->table);
- }
- else if (BYTE_TABLE_P (ct->table))
- {
- ctnew->table = copy_byte_table (ct->table);
- }
- else if (!UNBOUNDP (ct->table))
- ctnew->table = ct->table;
-#else /* non UTF2000 */
-
- for (i = 0; i < NUM_ASCII_CHARS; i++)
- {
- Lisp_Object new = ct->ascii[i];
-#ifdef MULE
- assert (! (CHAR_TABLE_ENTRYP (new)));
-#endif /* MULE */
- ctnew->ascii[i] = new;
- }
-
-#ifdef MULE
-
- for (i = 0; i < NUM_LEADING_BYTES; i++)
- {
- Lisp_Object new = ct->level1[i];
- if (CHAR_TABLE_ENTRYP (new))
- ctnew->level1[i] = copy_char_table_entry (new);
- else
- ctnew->level1[i] = new;
- }
-
-#endif /* MULE */
-#endif /* non UTF2000 */
-
-#ifndef UTF2000
- if (CHAR_TABLEP (ct->mirror_table))
- ctnew->mirror_table = Fcopy_char_table (ct->mirror_table);
- else
- ctnew->mirror_table = ct->mirror_table;
-#endif
- ctnew->next_table = Qnil;
- XSETCHAR_TABLE (obj, ctnew);
- if (ctnew->type == CHAR_TABLE_TYPE_SYNTAX)
- {
- ctnew->next_table = Vall_syntax_tables;
- Vall_syntax_tables = obj;
- }
- return obj;
-}
-
-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))
- outrange->type = CHARTAB_RANGE_ALL;
-#ifdef UTF2000
- else if (EQ (range, Qnil))
- outrange->type = CHARTAB_RANGE_DEFAULT;
-#endif
- else if (CHAR_OR_CHAR_INTP (range))
- {
- outrange->type = CHARTAB_RANGE_CHAR;
- outrange->ch = XCHAR_OR_CHAR_INT (range);
- }
-#ifndef MULE
- else
- signal_simple_error ("Range must be t or a character", range);
-#else /* MULE */
- else if (VECTORP (range))
- {
- Lisp_Vector *vec = XVECTOR (range);
- Lisp_Object *elts = vector_data (vec);
- 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)
- signal_simple_error ("Charset in row vector must be multi-byte",
- outrange->charset);
- else
- {
- 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
- ABORT ();
- }
- else
- {
- if (!CHARSETP (range) && !SYMBOLP (range))
- signal_simple_error
- ("Char table range must be t, charset, char, or vector", range);
- outrange->type = CHARTAB_RANGE_CHARSET;
- outrange->charset = Fget_charset (range);
- }
-#endif /* MULE */
-}
-
-#if defined(MULE)&&!defined(UTF2000)
-
-/* called from CHAR_TABLE_VALUE(). */
-Lisp_Object
-get_non_ascii_char_table_value (Lisp_Char_Table *ct, Charset_ID leading_byte,
- Emchar c)
-{
- Lisp_Object val;
-#ifdef UTF2000
- Lisp_Object charset;
-#else
- Lisp_Object charset = CHARSET_BY_LEADING_BYTE (leading_byte);
-#endif
- int byte1, byte2;
-
-#ifdef UTF2000
- BREAKUP_CHAR (c, charset, byte1, byte2);
-#else
- BREAKUP_CHAR_1_UNSAFE (c, charset, byte1, byte2);
-#endif
- val = ct->level1[leading_byte - MIN_LEADING_BYTE];
- if (CHAR_TABLE_ENTRYP (val))
- {
- Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
- val = cte->level2[byte1 - 32];
- if (CHAR_TABLE_ENTRYP (val))
- {
- cte = XCHAR_TABLE_ENTRY (val);
- assert (byte2 >= 32);
- val = cte->level2[byte2 - 32];
- assert (!CHAR_TABLE_ENTRYP (val));
- }
- }
-
- return val;
-}
-
-#endif /* MULE */
-
-Lisp_Object
-get_char_table (Emchar ch, Lisp_Char_Table *ct)
-{
-#ifdef UTF2000
- {
- Lisp_Object ret = get_char_id_table (ct, ch);
-
-#ifdef HAVE_CHISE
- if (NILP (ret))
- {
- if (EQ (CHAR_TABLE_NAME (ct), Qdowncase))
- ret = Fchar_feature (make_char (ch), Q_lowercase, Qnil,
- Qnil, Qnil);
- else if (EQ (CHAR_TABLE_NAME (ct), Qflippedcase))
- ret = Fchar_feature (make_char (ch), Q_uppercase, Qnil,
- Qnil, Qnil);
- if (CONSP (ret))
- {
- ret = XCAR (ret);
- if (CONSP (ret))
- ret = Ffind_char (ret);
- }
- }
-#endif
- return ret;
- }
-#elif defined(MULE)
- {
- Lisp_Object charset;
- int byte1, byte2;
- Lisp_Object val;
-
- BREAKUP_CHAR (ch, charset, byte1, byte2);
-
- if (EQ (charset, Vcharset_ascii))
- val = ct->ascii[byte1];
- else if (EQ (charset, Vcharset_control_1))
- val = ct->ascii[byte1 + 128];
- else
- {
- int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
- val = ct->level1[lb];
- if (CHAR_TABLE_ENTRYP (val))
- {
- Lisp_Char_Table_Entry *cte = XCHAR_TABLE_ENTRY (val);
- val = cte->level2[byte1 - 32];
- if (CHAR_TABLE_ENTRYP (val))
- {
- cte = XCHAR_TABLE_ENTRY (val);
- assert (byte2 >= 32);
- val = cte->level2[byte2 - 32];
- assert (!CHAR_TABLE_ENTRYP (val));
- }
- }
- }
-
- return val;
- }
-#else /* not MULE */
- return ct->ascii[(unsigned char)ch];
-#endif /* not MULE */
-}
-
-
-DEFUN ("get-char-table", Fget_char_table, 2, 2, 0, /*
-Find value for CHARACTER in CHAR-TABLE.
-*/
- (character, char_table))
-{
- CHECK_CHAR_TABLE (char_table);
- CHECK_CHAR_COERCE_INT (character);
-
- return get_char_table (XCHAR (character), XCHAR_TABLE (char_table));
-}
-
-DEFUN ("get-range-char-table", Fget_range_char_table, 2, 3, 0, /*
-Find value for a range in CHAR-TABLE.
-If there is more than one value, return MULTI (defaults to nil).
-*/
- (range, char_table, multi))
-{
- Lisp_Char_Table *ct;
- struct chartab_range rainj;
-
- if (CHAR_OR_CHAR_INTP (range))
- return Fget_char_table (range, char_table);
- CHECK_CHAR_TABLE (char_table);
- ct = XCHAR_TABLE (char_table);
-
- decode_char_table_range (range, &rainj);
- switch (rainj.type)
- {
- case CHARTAB_RANGE_ALL:
- {
-#ifdef UTF2000
- if (UINT8_BYTE_TABLE_P (ct->table))
- return multi;
- else if (UINT16_BYTE_TABLE_P (ct->table))
- return multi;
- else if (BYTE_TABLE_P (ct->table))
- return multi;
- else
- return ct->table;
-#else /* non UTF2000 */
- int i;
- Lisp_Object first = ct->ascii[0];
-
- for (i = 1; i < NUM_ASCII_CHARS; i++)
- if (!EQ (first, ct->ascii[i]))
- return multi;
-
-#ifdef MULE
- for (i = MIN_LEADING_BYTE; i < MIN_LEADING_BYTE + NUM_LEADING_BYTES;
- i++)
- {
- if (!CHARSETP (CHARSET_BY_LEADING_BYTE (i))
- || i == LEADING_BYTE_ASCII
- || i == LEADING_BYTE_CONTROL_1)
- continue;
- if (!EQ (first, ct->level1[i - MIN_LEADING_BYTE]))
- return multi;
- }
-#endif /* MULE */
-
- return first;
-#endif /* non UTF2000 */
- }
-
-#ifdef MULE
- case CHARTAB_RANGE_CHARSET:
-#ifdef UTF2000
- return multi;
-#else
- if (EQ (rainj.charset, Vcharset_ascii))
- {
- int i;
- Lisp_Object first = ct->ascii[0];
-
- for (i = 1; i < 128; i++)
- if (!EQ (first, ct->ascii[i]))
- return multi;
- return first;
- }
-
- if (EQ (rainj.charset, Vcharset_control_1))
- {
- int i;
- Lisp_Object first = ct->ascii[128];
-
- for (i = 129; i < 160; i++)
- if (!EQ (first, ct->ascii[i]))
- return multi;
- return first;
- }
-
- {
- Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
- MIN_LEADING_BYTE];
- if (CHAR_TABLE_ENTRYP (val))
- return multi;
- return val;
- }
-#endif
-
- case CHARTAB_RANGE_ROW:
-#ifdef UTF2000
- return multi;
-#else
- {
- Lisp_Object val = ct->level1[XCHARSET_LEADING_BYTE (rainj.charset) -
- MIN_LEADING_BYTE];
- if (!CHAR_TABLE_ENTRYP (val))
- return val;
- val = XCHAR_TABLE_ENTRY (val)->level2[rainj.row - 32];
- if (CHAR_TABLE_ENTRYP (val))
- return multi;
- return val;
- }
-#endif /* not UTF2000 */
-#endif /* not MULE */
-
-#ifdef UTF2000
- case CHARTAB_RANGE_DEFAULT:
- return ct->default_value;
-#endif /* not UTF2000 */
-
- default:
- ABORT ();
- }
-
- return Qnil; /* not reached */
-}
-
-static int
-check_valid_char_table_value (Lisp_Object value, enum char_table_type type,
- Error_behavior errb)
-{
- switch (type)
- {
- case CHAR_TABLE_TYPE_SYNTAX:
- if (!ERRB_EQ (errb, ERROR_ME))
- return INTP (value) || (CONSP (value) && INTP (XCAR (value))
- && CHAR_OR_CHAR_INTP (XCDR (value)));
- if (CONSP (value))
- {
- Lisp_Object cdr = XCDR (value);
- CHECK_INT (XCAR (value));
- CHECK_CHAR_COERCE_INT (cdr);
- }
- else
- CHECK_INT (value);
- break;
-
-#ifdef MULE
- case CHAR_TABLE_TYPE_CATEGORY:
- if (!ERRB_EQ (errb, ERROR_ME))
- return CATEGORY_TABLE_VALUEP (value);
- CHECK_CATEGORY_TABLE_VALUE (value);
- break;
-#endif /* MULE */
-
- case CHAR_TABLE_TYPE_GENERIC:
- return 1;
-
- case CHAR_TABLE_TYPE_DISPLAY:
- /* #### fix this */
- maybe_signal_simple_error ("Display char tables not yet implemented",
- value, Qchar_table, errb);
- return 0;
-
- case CHAR_TABLE_TYPE_CHAR:
- if (!ERRB_EQ (errb, ERROR_ME))
- return CHAR_OR_CHAR_INTP (value);
- CHECK_CHAR_COERCE_INT (value);
- break;
-
- default:
- ABORT ();
- }
-
- return 0; /* not reached */
-}
-
-static Lisp_Object
-canonicalize_char_table_value (Lisp_Object value, enum char_table_type type)
-{
- switch (type)
- {
- case CHAR_TABLE_TYPE_SYNTAX:
- if (CONSP (value))
- {
- Lisp_Object car = XCAR (value);
- Lisp_Object cdr = XCDR (value);
- CHECK_CHAR_COERCE_INT (cdr);
- return Fcons (car, cdr);
- }
- break;
- case CHAR_TABLE_TYPE_CHAR:
- CHECK_CHAR_COERCE_INT (value);
- break;
- default:
- break;
- }
- return value;
-}
-
-DEFUN ("valid-char-table-value-p", Fvalid_char_table_value_p, 2, 2, 0, /*
-Return non-nil if VALUE is a valid value for CHAR-TABLE-TYPE.
-*/
- (value, char_table_type))
-{
- enum char_table_type type = symbol_to_char_table_type (char_table_type);
-
- return check_valid_char_table_value (value, type, ERROR_ME_NOT) ? Qt : Qnil;
-}
-
-DEFUN ("check-valid-char-table-value", Fcheck_valid_char_table_value, 2, 2, 0, /*
-Signal an error if VALUE is not a valid value for CHAR-TABLE-TYPE.
-*/
- (value, char_table_type))
-{
- enum char_table_type type = symbol_to_char_table_type (char_table_type);
-
- check_valid_char_table_value (value, type, ERROR_ME);
- return Qnil;
-}
-
-#ifdef UTF2000
-Lisp_Char_Table* char_attribute_table_to_put;
-Lisp_Object Qput_char_table_map_function;
-Lisp_Object value_to_put;
-
-DEFUN ("put-char-table-map-function",
- Fput_char_table_map_function, 2, 2, 0, /*
-For internal use. Don't use it.
-*/
- (c, value))
-{
- put_char_id_table_0 (char_attribute_table_to_put,
- XCHAR (c), value_to_put);
- return Qnil;
-}
-#endif
-
-/* Assign VAL to all characters in RANGE in char table CT. */
-
-void
-put_char_table (Lisp_Char_Table *ct, struct chartab_range *range,
- Lisp_Object val)
-{
- switch (range->type)
- {
- case CHARTAB_RANGE_ALL:
- fill_char_table (ct, val);
- return; /* avoid the duplicate call to update_syntax_table() below,
- since fill_char_table() also did that. */
-
-#ifdef UTF2000
- case CHARTAB_RANGE_DEFAULT:
- ct->default_value = val;
- return;
-#endif
-
-#ifdef MULE
- case CHARTAB_RANGE_CHARSET:
-#ifdef UTF2000
- {
- Lisp_Object encoding_table = XCHARSET_ENCODING_TABLE (range->charset);
-
- if ( CHAR_TABLEP (encoding_table) )
- {
- Lisp_Object mother = XCHARSET_MOTHER (range->charset);
-
- char_attribute_table_to_put = ct;
- value_to_put = val;
- Fmap_char_attribute (Qput_char_table_map_function,
- XCHAR_TABLE_NAME (encoding_table),
- Qnil);
- if ( CHARSETP (mother) )
- {
- struct chartab_range r;
-
- r.type = CHARTAB_RANGE_CHARSET;
- r.charset = mother;
- put_char_table (ct, &r, val);
- }
- }
-#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))
- {
- int i;
- for (i = 0; i < 128; i++)
- ct->ascii[i] = val;
- }
- else if (EQ (range->charset, Vcharset_control_1))
- {
- int i;
- for (i = 128; i < 160; i++)
- ct->ascii[i] = val;
- }
- else
- {
- int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
- ct->level1[lb] = val;
- }
-#endif
- break;
-
- case CHARTAB_RANGE_ROW:
-#ifdef UTF2000
- {
- int cell_min, cell_max, i;
-
- 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, 0);
-
- if ( charset_code_point (range->charset, ch, 0) >= 0 )
- put_char_id_table_0 (ct, ch, val);
- }
- }
-#else
- {
- Lisp_Char_Table_Entry *cte;
- int lb = XCHARSET_LEADING_BYTE (range->charset) - MIN_LEADING_BYTE;
- /* make sure that there is a separate entry for the row. */
- if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
- ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
- cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
- cte->level2[range->row - 32] = val;
- }
-#endif /* not UTF2000 */
- break;
-#endif /* MULE */
-
- case CHARTAB_RANGE_CHAR:
-#ifdef UTF2000
- put_char_id_table_0 (ct, range->ch, val);
- break;
-#elif defined(MULE)
- {
- Lisp_Object charset;
- int byte1, byte2;
-
- BREAKUP_CHAR (range->ch, charset, byte1, byte2);
- if (EQ (charset, Vcharset_ascii))
- ct->ascii[byte1] = val;
- else if (EQ (charset, Vcharset_control_1))
- ct->ascii[byte1 + 128] = val;
- else
- {
- Lisp_Char_Table_Entry *cte;
- int lb = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
- /* make sure that there is a separate entry for the row. */
- if (!CHAR_TABLE_ENTRYP (ct->level1[lb]))
- ct->level1[lb] = make_char_table_entry (ct->level1[lb]);
- cte = XCHAR_TABLE_ENTRY (ct->level1[lb]);
- /* now CTE is a char table entry for the charset;
- each entry is for a single row (or character of
- a one-octet charset). */
- if (XCHARSET_DIMENSION (charset) == 1)
- cte->level2[byte1 - 32] = val;
- else
- {
- /* assigning to one character in a two-octet charset. */
- /* make sure that the charset row contains a separate
- entry for each character. */
- if (!CHAR_TABLE_ENTRYP (cte->level2[byte1 - 32]))
- cte->level2[byte1 - 32] =
- make_char_table_entry (cte->level2[byte1 - 32]);
- cte = XCHAR_TABLE_ENTRY (cte->level2[byte1 - 32]);
- cte->level2[byte2 - 32] = val;
- }
- }
- }
-#else /* not MULE */
- ct->ascii[(unsigned char) (range->ch)] = val;
- break;
-#endif /* not MULE */
- }
-
-#ifndef UTF2000
- if (ct->type == CHAR_TABLE_TYPE_SYNTAX)
- update_syntax_table (ct);
-#endif
-}
-
-DEFUN ("put-char-table", Fput_char_table, 3, 3, 0, /*
-Set the value for chars in RANGE to be VALUE in CHAR-TABLE.
-
-RANGE specifies one or more characters to be affected and should be
-one of the following:
-
--- t (all characters are affected)
--- A charset (only allowed when Mule support is present)
--- A vector of two elements: a two-octet charset and a row number
- (only allowed when Mule support is present)
--- A single character
-
-VALUE must be a value appropriate for the type of CHAR-TABLE.
-See `valid-char-table-type-p'.
-*/
- (range, value, char_table))
-{
- Lisp_Char_Table *ct;
- struct chartab_range rainj;
-
- CHECK_CHAR_TABLE (char_table);
- ct = XCHAR_TABLE (char_table);
- check_valid_char_table_value (value, ct->type, ERROR_ME);
- decode_char_table_range (range, &rainj);
- value = canonicalize_char_table_value (value, ct->type);
- put_char_table (ct, &rainj, value);
- return Qnil;
-}
-
-#ifndef UTF2000
-/* Map FN over the ASCII chars in CT. */
-
-static int
-map_over_charset_ascii (Lisp_Char_Table *ct,
- int (*fn) (struct chartab_range *range,
- Lisp_Object val, void *arg),
- void *arg)
-{
- struct chartab_range rainj;
- int i, retval;
- int start = 0;
-#ifdef MULE
- int stop = 128;
-#else
- int stop = 256;
-#endif
-
- rainj.type = CHARTAB_RANGE_CHAR;
-
- for (i = start, retval = 0; i < stop && retval == 0; i++)
- {
- rainj.ch = (Emchar) i;
- retval = (fn) (&rainj, ct->ascii[i], arg);
- }
-
- return retval;
-}
-
-#ifdef MULE
-
-/* Map FN over the Control-1 chars in CT. */
-
-static int
-map_over_charset_control_1 (Lisp_Char_Table *ct,
- int (*fn) (struct chartab_range *range,
- Lisp_Object val, void *arg),
- void *arg)
-{
- struct chartab_range rainj;
- int i, retval;
- int start = 128;
- int stop = start + 32;
-
- rainj.type = CHARTAB_RANGE_CHAR;
-
- for (i = start, retval = 0; i < stop && retval == 0; i++)
- {
- rainj.ch = (Emchar) (i);
- retval = (fn) (&rainj, ct->ascii[i], arg);
- }
-
- return retval;
-}
-
-/* Map FN over the row ROW of two-byte charset CHARSET.
- There must be a separate value for that row in the char table.
- CTE specifies the char table entry for CHARSET. */
-
-static int
-map_over_charset_row (Lisp_Char_Table_Entry *cte,
- Lisp_Object charset, int row,
- int (*fn) (struct chartab_range *range,
- Lisp_Object val, void *arg),
- void *arg)
-{
- Lisp_Object val = cte->level2[row - 32];
-
- if (!CHAR_TABLE_ENTRYP (val))
- {
- struct chartab_range rainj;
-
- rainj.type = CHARTAB_RANGE_ROW;
- rainj.charset = charset;
- rainj.row = row;
- return (fn) (&rainj, val, arg);