aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa1997-11-08 03:05:44 +0000
committerKenichi Handa1997-11-08 03:05:44 +0000
commit733eafd8ed4bb3f97193f26e855ed4bf40bc9c23 (patch)
treecfc73c8b5cd9bfc30cbffdfadf08ea64a013b97e /src
parentc952af224541abd7cf8882e47d91fb3ba9adedf4 (diff)
downloademacs-733eafd8ed4bb3f97193f26e855ed4bf40bc9c23.tar.gz
emacs-733eafd8ed4bb3f97193f26e855ed4bf40bc9c23.zip
(find_charset_in_str): Handle the case that STR
contains invalid multibyte-form.
Diffstat (limited to 'src')
-rw-r--r--src/charset.c74
1 files changed, 39 insertions, 35 deletions
diff --git a/src/charset.c b/src/charset.c
index 56dc15e78da..3241d9b7194 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -545,9 +545,7 @@ find_charset_in_str (str, len, charsets, table)
545 int len, *charsets; 545 int len, *charsets;
546 Lisp_Object table; 546 Lisp_Object table;
547{ 547{
548 int num = 0; 548 register int num = 0, c;
549 int cmpcharp = 0;
550 unsigned char str_work[4], *str_tmp;
551 549
552 if (! CHAR_TABLE_P (table)) 550 if (! CHAR_TABLE_P (table))
553 table = Qnil; 551 table = Qnil;
@@ -555,46 +553,52 @@ find_charset_in_str (str, len, charsets, table)
555 while (len > 0) 553 while (len > 0)
556 { 554 {
557 int bytes, charset; 555 int bytes, charset;
556 c = *str;
558 557
559 if (*str == LEADING_CODE_COMPOSITION) 558 if (c == LEADING_CODE_COMPOSITION)
560 { 559 {
561 str++; 560 int cmpchar_id = str_cmpchar_id (str, len);
562 len--; 561 GLYPH *glyph;
563 cmpcharp = 1;
564 }
565 else if (CHAR_HEAD_P (str))
566 cmpcharp = 0;
567 562
568 if (cmpcharp) 563 if (cmpchar_id > 0)
569 {
570 if (*str == 0xA0)
571 {
572 str++;
573 len--;
574 str_work[0] = *str & 0x7F;
575 }
576 else
577 { 564 {
578 bcopy (str, str_work, min (4, len)); 565 struct cmpchar_info *cmpcharp = cmpchar_table[cmpchar_id];
579 str_work[0] -= 0x20; 566 int i;
567
568 for (i = 0; i < cmpcharp->glyph_len; i++)
569 {
570 c = cmpcharp->glyph[i];
571 if (!NILP (table))
572 {
573 if ((c = unify_char (table, c, 0, 0, 0)) < 0)
574 c = cmpcharp->glyph[i];
575 }
576 if ((charset = CHAR_CHARSET (c)) < 0)
577 charset = CHARSET_ASCII;
578 if (!charsets[charset])
579 {
580 charsets[charset] = 1;
581 num += 1;
582 }
583 }
584 str += cmpcharp->len;
585 len -= cmpcharp->len;
586 continue;
580 } 587 }
581 str_tmp = str_work;
582 }
583 else
584 str_tmp = str;
585
586 bytes = BYTES_BY_CHAR_HEAD (*str_tmp);
587 588
588 if (NILP (table)) 589 charset = CHARSET_ASCII;
589 charset = CHARSET_AT (str_tmp); 590 bytes = 1;
591 }
590 else 592 else
591 { 593 {
592 int c; 594 c = STRING_CHAR_AND_LENGTH (str, len, bytes);
593 unsigned char c1, c2; 595 if (! NILP (table))
594 596 {
595 SPLIT_STRING(str_tmp, bytes, charset, c1, c2); 597 int c1 = unify_char (table, c, 0, 0, 0);
596 if ((c = unify_char (table, -1, charset, c1, c2)) >= 0) 598 if (c1 >= 0)
597 charset = CHAR_CHARSET (c); 599 c = c1;
600 }
601 charset = CHAR_CHARSET (c);
598 } 602 }
599 603
600 if (!charsets[charset]) 604 if (!charsets[charset])