comparison src/chartab.c @ 109423:ae5ef13849d8

Merge from mainline.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Sun, 04 Jul 2010 22:11:22 +0000
parents aec1143e8d85
children c25c24812fb1
comparison
equal deleted inserted replaced
109422:bcedeeedc5fb 109423:ae5ef13849d8
90 XSETCHAR_TABLE (vector, XCHAR_TABLE (vector)); 90 XSETCHAR_TABLE (vector, XCHAR_TABLE (vector));
91 return vector; 91 return vector;
92 } 92 }
93 93
94 static Lisp_Object 94 static Lisp_Object
95 make_sub_char_table (depth, min_char, defalt) 95 make_sub_char_table (int depth, int min_char, Lisp_Object defalt)
96 int depth, min_char;
97 Lisp_Object defalt;
98 { 96 {
99 Lisp_Object table; 97 Lisp_Object table;
100 int size = VECSIZE (struct Lisp_Sub_Char_Table) - 1 + chartab_size[depth]; 98 int size = VECSIZE (struct Lisp_Sub_Char_Table) - 1 + chartab_size[depth];
101 99
102 table = Fmake_vector (make_number (size), defalt); 100 table = Fmake_vector (make_number (size), defalt);
106 104
107 return table; 105 return table;
108 } 106 }
109 107
110 static Lisp_Object 108 static Lisp_Object
111 char_table_ascii (table) 109 char_table_ascii (Lisp_Object table)
112 Lisp_Object table;
113 { 110 {
114 Lisp_Object sub; 111 Lisp_Object sub;
115 112
116 sub = XCHAR_TABLE (table)->contents[0]; 113 sub = XCHAR_TABLE (table)->contents[0];
117 if (! SUB_CHAR_TABLE_P (sub)) 114 if (! SUB_CHAR_TABLE_P (sub))
121 return sub; 118 return sub;
122 return XSUB_CHAR_TABLE (sub)->contents[0]; 119 return XSUB_CHAR_TABLE (sub)->contents[0];
123 } 120 }
124 121
125 Lisp_Object 122 Lisp_Object
126 copy_sub_char_table (table) 123 copy_sub_char_table (Lisp_Object table)
127 Lisp_Object table;
128 { 124 {
129 Lisp_Object copy; 125 Lisp_Object copy;
130 int depth = XINT (XSUB_CHAR_TABLE (table)->depth); 126 int depth = XINT (XSUB_CHAR_TABLE (table)->depth);
131 int min_char = XINT (XSUB_CHAR_TABLE (table)->min_char); 127 int min_char = XINT (XSUB_CHAR_TABLE (table)->min_char);
132 Lisp_Object val; 128 Lisp_Object val;
146 return copy; 142 return copy;
147 } 143 }
148 144
149 145
150 Lisp_Object 146 Lisp_Object
151 copy_char_table (table) 147 copy_char_table (Lisp_Object table)
152 Lisp_Object table;
153 { 148 {
154 Lisp_Object copy; 149 Lisp_Object copy;
155 int size = XCHAR_TABLE (table)->size & PSEUDOVECTOR_SIZE_MASK; 150 int size = XCHAR_TABLE (table)->size & PSEUDOVECTOR_SIZE_MASK;
156 int i; 151 int i;
157 152
173 XSETCHAR_TABLE (copy, XCHAR_TABLE (copy)); 168 XSETCHAR_TABLE (copy, XCHAR_TABLE (copy));
174 return copy; 169 return copy;
175 } 170 }
176 171
177 Lisp_Object 172 Lisp_Object
178 sub_char_table_ref (table, c) 173 sub_char_table_ref (Lisp_Object table, int c)
179 Lisp_Object table;
180 int c;
181 { 174 {
182 struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table); 175 struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table);
183 int depth = XINT (tbl->depth); 176 int depth = XINT (tbl->depth);
184 int min_char = XINT (tbl->min_char); 177 int min_char = XINT (tbl->min_char);
185 Lisp_Object val; 178 Lisp_Object val;
189 val = sub_char_table_ref (val, c); 182 val = sub_char_table_ref (val, c);
190 return val; 183 return val;
191 } 184 }
192 185
193 Lisp_Object 186 Lisp_Object
194 char_table_ref (table, c) 187 char_table_ref (Lisp_Object table, int c)
195 Lisp_Object table;
196 int c;
197 { 188 {
198 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); 189 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table);
199 Lisp_Object val; 190 Lisp_Object val;
200 191
201 if (ASCII_CHAR_P (c)) 192 if (ASCII_CHAR_P (c))
218 } 209 }
219 return val; 210 return val;
220 } 211 }
221 212
222 static Lisp_Object 213 static Lisp_Object
223 sub_char_table_ref_and_range (table, c, from, to, defalt) 214 sub_char_table_ref_and_range (Lisp_Object table, int c, int *from, int *to, Lisp_Object defalt)
224 Lisp_Object table;
225 int c;
226 int *from, *to;
227 Lisp_Object defalt;
228 { 215 {
229 struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table); 216 struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table);
230 int depth = XINT (tbl->depth); 217 int depth = XINT (tbl->depth);
231 int min_char = XINT (tbl->min_char); 218 int min_char = XINT (tbl->min_char);
232 int max_char = min_char + chartab_chars[depth - 1] - 1; 219 int max_char = min_char + chartab_chars[depth - 1] - 1;
284 and *TO to cover characters (containing C) that have the same value 271 and *TO to cover characters (containing C) that have the same value
285 as C. It is not assured that the values of (*FROM - 1) and (*TO + 272 as C. It is not assured that the values of (*FROM - 1) and (*TO +
286 1) are different from that of C. */ 273 1) are different from that of C. */
287 274
288 Lisp_Object 275 Lisp_Object
289 char_table_ref_and_range (table, c, from, to) 276 char_table_ref_and_range (Lisp_Object table, int c, int *from, int *to)
290 Lisp_Object table;
291 int c;
292 int *from, *to;
293 { 277 {
294 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); 278 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table);
295 int index = CHARTAB_IDX (c, 0, 0), idx; 279 int index = CHARTAB_IDX (c, 0, 0), idx;
296 Lisp_Object val; 280 Lisp_Object val;
297 281
361 (SUBTABLE) = make_sub_char_table ((DEPTH), (MIN_CHAR), (SUBTABLE)); \ 345 (SUBTABLE) = make_sub_char_table ((DEPTH), (MIN_CHAR), (SUBTABLE)); \
362 } while (0) 346 } while (0)
363 347
364 348
365 static void 349 static void
366 sub_char_table_set (table, c, val) 350 sub_char_table_set (Lisp_Object table, int c, Lisp_Object val)
367 Lisp_Object table;
368 int c;
369 Lisp_Object val;
370 { 351 {
371 struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table); 352 struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table);
372 int depth = XINT ((tbl)->depth); 353 int depth = XINT ((tbl)->depth);
373 int min_char = XINT ((tbl)->min_char); 354 int min_char = XINT ((tbl)->min_char);
374 int i = CHARTAB_IDX (c, depth, min_char); 355 int i = CHARTAB_IDX (c, depth, min_char);
388 sub_char_table_set (sub, c, val); 369 sub_char_table_set (sub, c, val);
389 } 370 }
390 } 371 }
391 372
392 Lisp_Object 373 Lisp_Object
393 char_table_set (table, c, val) 374 char_table_set (Lisp_Object table, int c, Lisp_Object val)
394 Lisp_Object table;
395 int c;
396 Lisp_Object val;
397 { 375 {
398 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); 376 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table);
399 377
400 if (ASCII_CHAR_P (c) 378 if (ASCII_CHAR_P (c)
401 && SUB_CHAR_TABLE_P (tbl->ascii)) 379 && SUB_CHAR_TABLE_P (tbl->ascii))
419 } 397 }
420 return val; 398 return val;
421 } 399 }
422 400
423 static void 401 static void
424 sub_char_table_set_range (table, depth, min_char, from, to, val) 402 sub_char_table_set_range (Lisp_Object *table, int depth, int min_char, int from, int to, Lisp_Object val)
425 Lisp_Object *table;
426 int depth;
427 int min_char;
428 int from, to;
429 Lisp_Object val;
430 { 403 {
431 int max_char = min_char + chartab_chars[depth] - 1; 404 int max_char = min_char + chartab_chars[depth] - 1;
432 405
433 if (depth == 3 || (from <= min_char && to >= max_char)) 406 if (depth == 3 || (from <= min_char && to >= max_char))
434 *table = val; 407 *table = val;
452 } 425 }
453 } 426 }
454 427
455 428
456 Lisp_Object 429 Lisp_Object
457 char_table_set_range (table, from, to, val) 430 char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val)
458 Lisp_Object table;
459 int from, to;
460 Lisp_Object val;
461 { 431 {
462 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); 432 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table);
463 Lisp_Object *contents = tbl->contents; 433 Lisp_Object *contents = tbl->contents;
464 int i, min_char; 434 int i, min_char;
465 435
638 608
639 /* Look up the element in TABLE at index CH, and return it as an 609 /* Look up the element in TABLE at index CH, and return it as an
640 integer. If the element is not a character, return CH itself. */ 610 integer. If the element is not a character, return CH itself. */
641 611
642 int 612 int
643 char_table_translate (table, ch) 613 char_table_translate (Lisp_Object table, int ch)
644 Lisp_Object table;
645 int ch;
646 { 614 {
647 Lisp_Object value; 615 Lisp_Object value;
648 value = Faref (table, make_number (ch)); 616 value = Faref (table, make_number (ch));
649 if (! CHARACTERP (value)) 617 if (! CHARACTERP (value))
650 return ch; 618 return ch;
651 return XINT (value); 619 return XINT (value);
652 } 620 }
653 621
654 static Lisp_Object 622 static Lisp_Object
655 optimize_sub_char_table (table, test) 623 optimize_sub_char_table (Lisp_Object table, Lisp_Object test)
656 Lisp_Object table, test;
657 { 624 {
658 struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table); 625 struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table);
659 int depth = XINT (tbl->depth); 626 int depth = XINT (tbl->depth);
660 Lisp_Object elt, this; 627 Lisp_Object elt, this;
661 int i, optimizable; 628 int i, optimizable;
723 following characters in TABLE have the same value. */ 690 following characters in TABLE have the same value. */
724 691
725 static Lisp_Object 692 static Lisp_Object
726 map_sub_char_table (c_function, function, table, arg, val, range, 693 map_sub_char_table (c_function, function, table, arg, val, range,
727 default_val, parent) 694 default_val, parent)
728 void (*c_function) P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); 695 void (*c_function) (Lisp_Object, Lisp_Object, Lisp_Object);
729 Lisp_Object function, table, arg, val, range, default_val, parent; 696 Lisp_Object function, table, arg, val, range, default_val, parent;
730 { 697 {
731 /* Pointer to the elements of TABLE. */ 698 /* Pointer to the elements of TABLE. */
732 Lisp_Object *contents; 699 Lisp_Object *contents;
733 /* Depth of TABLE. */ 700 /* Depth of TABLE. */
838 character or group of characters that share a value. 805 character or group of characters that share a value.
839 806
840 ARG is passed to C_FUNCTION when that is called. */ 807 ARG is passed to C_FUNCTION when that is called. */
841 808
842 void 809 void
843 map_char_table (c_function, function, table, arg) 810 map_char_table (void (*c_function) (Lisp_Object, Lisp_Object, Lisp_Object), Lisp_Object function, Lisp_Object table, Lisp_Object arg)
844 void (*c_function) P_ ((Lisp_Object, Lisp_Object, Lisp_Object));
845 Lisp_Object function, table, arg;
846 { 811 {
847 Lisp_Object range, val; 812 Lisp_Object range, val;
848 struct gcpro gcpro1, gcpro2, gcpro3; 813 struct gcpro gcpro1, gcpro2, gcpro3;
849 814
850 range = Fcons (make_number (0), make_number (MAX_CHAR)); 815 range = Fcons (make_number (0), make_number (MAX_CHAR));
913 878
914 879
915 static void 880 static void
916 map_sub_char_table_for_charset (c_function, function, table, arg, range, 881 map_sub_char_table_for_charset (c_function, function, table, arg, range,
917 charset, from, to) 882 charset, from, to)
918 void (*c_function) P_ ((Lisp_Object, Lisp_Object)); 883 void (*c_function) (Lisp_Object, Lisp_Object);
919 Lisp_Object function, table, arg, range; 884 Lisp_Object function, table, arg, range;
920 struct charset *charset; 885 struct charset *charset;
921 unsigned from, to; 886 unsigned from, to;
922 { 887 {
923 struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table); 888 struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table);
1000 map_charset_chars. */ 965 map_charset_chars. */
1001 966
1002 void 967 void
1003 map_char_table_for_charset (c_function, function, table, arg, 968 map_char_table_for_charset (c_function, function, table, arg,
1004 charset, from, to) 969 charset, from, to)
1005 void (*c_function) P_ ((Lisp_Object, Lisp_Object)); 970 void (*c_function) (Lisp_Object, Lisp_Object);
1006 Lisp_Object function, table, arg; 971 Lisp_Object function, table, arg;
1007 struct charset *charset; 972 struct charset *charset;
1008 unsigned from, to; 973 unsigned from, to;
1009 { 974 {
1010 Lisp_Object range; 975 Lisp_Object range;
1047 UNGCPRO; 1012 UNGCPRO;
1048 } 1013 }
1049 1014
1050 1015
1051 void 1016 void
1052 syms_of_chartab () 1017 syms_of_chartab (void)
1053 { 1018 {
1054 defsubr (&Smake_char_table); 1019 defsubr (&Smake_char_table);
1055 defsubr (&Schar_table_parent); 1020 defsubr (&Schar_table_parent);
1056 defsubr (&Schar_table_subtype); 1021 defsubr (&Schar_table_subtype);
1057 defsubr (&Sset_char_table_parent); 1022 defsubr (&Sset_char_table_parent);