aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa1997-05-10 03:37:01 +0000
committerKenichi Handa1997-05-10 03:37:01 +0000
commit23d2a7f19452f709435f5570e33cd685dcba9578 (patch)
tree39840826ea8a6b23779973ea433f0006f20c989c /src
parent2db95897ddbd07ce5e62f1e13f4e5ed37ebf7e24 (diff)
downloademacs-23d2a7f19452f709435f5570e33cd685dcba9578.tar.gz
emacs-23d2a7f19452f709435f5570e33cd685dcba9578.zip
(unify_char): New function.
(Fdefine_charset): Doc-string modified. (find_charset_in_str): Add 4th arg TABLE which is a character unification table. (Ffind_charset_region): Add optional arg TABLE which is a character unification table. (Ffind_charset_string): Likewise.
Diffstat (limited to 'src')
-rw-r--r--src/charset.c82
1 files changed, 68 insertions, 14 deletions
diff --git a/src/charset.c b/src/charset.c
index fbed6283daa..3a4eec181a8 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -225,6 +225,40 @@ split_non_ascii_string (str, len, charset, c1, c2)
225 return 0; 225 return 0;
226} 226}
227 227
228/* Return a character unified with C (or a character made of CHARSET,
229 C1, and C2) in unification table TABLE. If no unification is found
230 in TABLE, return C. */
231unify_char (table, c, charset, c1, c2)
232 Lisp_Object table;
233 int c, charset, c1, c2;
234{
235 Lisp_Object ch;
236 int alt_charset, alt_c1, alt_c2, dimension;
237
238 if (c < 0) c = MAKE_CHAR (charset, c1, c2);
239 if (!CHAR_TABLE_P (table)
240 || (ch = Faref (table, make_number (c)), !INTEGERP (ch))
241 || XINT (ch) < 0)
242 return c;
243
244 SPLIT_CHAR (XFASTINT (ch), alt_charset, alt_c1, alt_c2);
245 dimension = CHARSET_DIMENSION (alt_charset);
246 if (dimension == 1 && alt_c1 > 0 || dimension == 2 && alt_c2 > 0)
247 /* CH is not a generic character, just return it. */
248 return XFASTINT (ch);
249
250 /* Since CH is a generic character, we must return a specific
251 charater which has the same position codes as C from CH. */
252 if (charset < 0)
253 SPLIT_CHAR (c, charset, c1, c2);
254 if (dimension != CHARSET_DIMENSION (charset))
255 /* We can't make such a character because of dimension mismatch. */
256 return c;
257 if (!alt_c1) alt_c1 = c1;
258 if (!alt_c2) alt_c2 = c2;
259 return MAKE_CHAR (alt_charset, c1, c2);
260}
261
228/* Update the table Vcharset_table with the given arguments (see the 262/* Update the table Vcharset_table with the given arguments (see the
229 document of `define-charset' for the meaning of each argument). 263 document of `define-charset' for the meaning of each argument).
230 Several other table contents are also updated. The caller should 264 Several other table contents are also updated. The caller should
@@ -390,7 +424,7 @@ get_new_private_charset_id (dimension, width)
390 424
391DEFUN ("define-charset", Fdefine_charset, Sdefine_charset, 3, 3, 0, 425DEFUN ("define-charset", Fdefine_charset, Sdefine_charset, 3, 3, 0,
392 "Define CHARSET-ID as the identification number of CHARSET with INFO-VECTOR.\n\ 426 "Define CHARSET-ID as the identification number of CHARSET with INFO-VECTOR.\n\
393If CHARSET-ID is nil, it is set automatically, which means CHARSET is\n\ 427If CHARSET-ID is nil, it is decided automatically, which means CHARSET is\n\
394 treated as a private charset.\n\ 428 treated as a private charset.\n\
395INFO-VECTOR is a vector of the format:\n\ 429INFO-VECTOR is a vector of the format:\n\
396 [DIMENSION CHARS WIDTH DIRECTION ISO-FINAL-CHAR ISO-GRAPHIC-PLANE\n\ 430 [DIMENSION CHARS WIDTH DIRECTION ISO-FINAL-CHAR ISO-GRAPHIC-PLANE\n\
@@ -494,19 +528,36 @@ CHARSET should be defined by `defined-charset' in advance.")
494 528
495/* Return number of different charsets in STR of length LEN. In 529/* Return number of different charsets in STR of length LEN. In
496 addition, for each found charset N, CHARSETS[N] is set 1. The 530 addition, for each found charset N, CHARSETS[N] is set 1. The
497 caller should allocate CHARSETS (MAX_CHARSET + 1 bytes) in advance. */ 531 caller should allocate CHARSETS (MAX_CHARSET + 1 bytes) in advance.
532 It may lookup a unification table TABLE if supplied. */
498 533
499int 534int
500find_charset_in_str (str, len, charsets) 535find_charset_in_str (str, len, charsets, table)
501 unsigned char *str, *charsets; 536 unsigned char *str, *charsets;
502 int len; 537 int len;
538 Lisp_Object table;
503{ 539{
504 int num = 0; 540 int num = 0;
505 541
542 if (! CHAR_TABLE_P (table))
543 table = Qnil;
544
506 while (len > 0) 545 while (len > 0)
507 { 546 {
508 int bytes = BYTES_BY_CHAR_HEAD (*str); 547 int bytes = BYTES_BY_CHAR_HEAD (*str);
509 int charset = CHARSET_AT (str); 548 int charset;
549
550 if (NILP (table))
551 charset = CHARSET_AT (str);
552 else
553 {
554 int c, charset;
555 unsigned char c1, c2;
556
557 SPLIT_STRING(str, bytes, charset, c1, c2);
558 if ((c = unify_char (table, -1, charset, c1, c2)) >= 0)
559 charset = CHAR_CHARSET (c);
560 }
510 561
511 if (!charsets[charset]) 562 if (!charsets[charset])
512 { 563 {
@@ -520,11 +571,12 @@ find_charset_in_str (str, len, charsets)
520} 571}
521 572
522DEFUN ("find-charset-region", Ffind_charset_region, Sfind_charset_region, 573DEFUN ("find-charset-region", Ffind_charset_region, Sfind_charset_region,
523 2, 2, 0, 574 2, 3, 0,
524 "Return a list of charsets in the region between BEG and END.\n\ 575 "Return a list of charsets in the region between BEG and END.\n\
525BEG and END are buffer positions.") 576BEG and END are buffer positions.\n\
526 (beg, end) 577Optional arg TABLE if non-nil is a unification table to look up.")
527 Lisp_Object beg, end; 578 (beg, end, table)
579 Lisp_Object beg, end, table;
528{ 580{
529 char charsets[MAX_CHARSET + 1]; 581 char charsets[MAX_CHARSET + 1];
530 int from, to, stop, i; 582 int from, to, stop, i;
@@ -538,7 +590,7 @@ BEG and END are buffer positions.")
538 bzero (charsets, MAX_CHARSET + 1); 590 bzero (charsets, MAX_CHARSET + 1);
539 while (1) 591 while (1)
540 { 592 {
541 find_charset_in_str (POS_ADDR (from), stop - from, charsets); 593 find_charset_in_str (POS_ADDR (from), stop - from, charsets, table);
542 if (stop < to) 594 if (stop < to)
543 from = stop, stop = to; 595 from = stop, stop = to;
544 else 596 else
@@ -552,10 +604,11 @@ BEG and END are buffer positions.")
552} 604}
553 605
554DEFUN ("find-charset-string", Ffind_charset_string, Sfind_charset_string, 606DEFUN ("find-charset-string", Ffind_charset_string, Sfind_charset_string,
555 1, 1, 0, 607 1, 2, 0,
556 "Return a list of charsets in STR.") 608 "Return a list of charsets in STR.\n\
557 (str) 609Optional arg TABLE if non-nil is a unification table to look up.")
558 Lisp_Object str; 610 (str, table)
611 Lisp_Object str, table;
559{ 612{
560 char charsets[MAX_CHARSET + 1]; 613 char charsets[MAX_CHARSET + 1];
561 int i; 614 int i;
@@ -563,7 +616,8 @@ DEFUN ("find-charset-string", Ffind_charset_string, Sfind_charset_string,
563 616
564 CHECK_STRING (str, 0); 617 CHECK_STRING (str, 0);
565 bzero (charsets, MAX_CHARSET + 1); 618 bzero (charsets, MAX_CHARSET + 1);
566 find_charset_in_str (XSTRING (str)->data, XSTRING (str)->size, charsets); 619 find_charset_in_str (XSTRING (str)->data, XSTRING (str)->size,
620 charsets, table);
567 val = Qnil; 621 val = Qnil;
568 for (i = MAX_CHARSET; i >= 0; i--) 622 for (i = MAX_CHARSET; i >= 0; i--)
569 if (charsets[i]) 623 if (charsets[i])