Mercurial > emacs
comparison src/coding.c @ 24065:7e291dea6141
(Fdecode_sjis_char): Decode Japanese Katakana character
correctly.
(Fencode_sjis_char): Encode Japanese Katakana character correctly.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Thu, 14 Jan 1999 01:20:35 +0000 |
| parents | d20160af7b6e |
| children | 38e26ebed6f7 |
comparison
equal
deleted
inserted
replaced
| 24064:e4cc744bdce5 | 24065:7e291dea6141 |
|---|---|
| 2094 do { \ | 2094 do { \ |
| 2095 int c_alt, charset_alt = (charset); \ | 2095 int c_alt, charset_alt = (charset); \ |
| 2096 if (!NILP (translation_table) \ | 2096 if (!NILP (translation_table) \ |
| 2097 && ((c_alt = translate_char (translation_table, \ | 2097 && ((c_alt = translate_char (translation_table, \ |
| 2098 -1, (charset), c1, c2)) >= 0)) \ | 2098 -1, (charset), c1, c2)) >= 0)) \ |
| 2099 SPLIT_CHAR (c_alt, charset_alt, c1, c2); \ | 2099 SPLIT_CHAR (c_alt, charset_alt, c1, c2); \ |
| 2100 if (charset_alt == CHARSET_ASCII || charset_alt < 0) \ | 2100 if (charset_alt == CHARSET_ASCII || charset_alt < 0) \ |
| 2101 DECODE_CHARACTER_ASCII (c1); \ | 2101 DECODE_CHARACTER_ASCII (c1); \ |
| 2102 else if (CHARSET_DIMENSION (charset_alt) == 1) \ | 2102 else if (CHARSET_DIMENSION (charset_alt) == 1) \ |
| 2103 DECODE_CHARACTER_DIMENSION1 (charset_alt, c1); \ | 2103 DECODE_CHARACTER_DIMENSION1 (charset_alt, c1); \ |
| 2104 else \ | 2104 else \ |
| 5016 coding.mode |= CODING_MODE_LAST_BLOCK; | 5016 coding.mode |= CODING_MODE_LAST_BLOCK; |
| 5017 return code_convert_string (string, &coding, encodep, Qt); | 5017 return code_convert_string (string, &coding, encodep, Qt); |
| 5018 } | 5018 } |
| 5019 | 5019 |
| 5020 DEFUN ("decode-sjis-char", Fdecode_sjis_char, Sdecode_sjis_char, 1, 1, 0, | 5020 DEFUN ("decode-sjis-char", Fdecode_sjis_char, Sdecode_sjis_char, 1, 1, 0, |
| 5021 "Decode a JISX0208 character of shift-jis encoding.\n\ | 5021 "Decode a Japanese character which has CODE in shift_jis encoding.\n\ |
| 5022 CODE is the character code in SJIS.\n\ | |
| 5023 Return the corresponding character.") | 5022 Return the corresponding character.") |
| 5024 (code) | 5023 (code) |
| 5025 Lisp_Object code; | 5024 Lisp_Object code; |
| 5026 { | 5025 { |
| 5027 unsigned char c1, c2, s1, s2; | 5026 unsigned char c1, c2, s1, s2; |
| 5028 Lisp_Object val; | 5027 Lisp_Object val; |
| 5029 | 5028 |
| 5030 CHECK_NUMBER (code, 0); | 5029 CHECK_NUMBER (code, 0); |
| 5031 s1 = (XFASTINT (code)) >> 8, s2 = (XFASTINT (code)) & 0xFF; | 5030 s1 = (XFASTINT (code)) >> 8, s2 = (XFASTINT (code)) & 0xFF; |
| 5032 DECODE_SJIS (s1, s2, c1, c2); | 5031 if (s1 == 0) |
| 5033 XSETFASTINT (val, MAKE_NON_ASCII_CHAR (charset_jisx0208, c1, c2)); | 5032 { |
| 5033 if (s2 < 0xA0 || s2 > 0xDF) | |
| 5034 error ("Invalid Shift JIS code: %s", XFASTINT (code)); | |
| 5035 XSETFASTINT (val, MAKE_NON_ASCII_CHAR (charset_katakana_jisx0201, s2, 0)); | |
| 5036 } | |
| 5037 else | |
| 5038 { | |
| 5039 if ((s1 < 0x80 || s1 > 0x9F && s1 < 0xE0 || s1 > 0xEF) | |
| 5040 || (s2 < 0x40 || s2 == 0x7F || s2 > 0xFC)) | |
| 5041 error ("Invalid Shift JIS code: %s", XFASTINT (code)); | |
| 5042 DECODE_SJIS (s1, s2, c1, c2); | |
| 5043 XSETFASTINT (val, MAKE_NON_ASCII_CHAR (charset_jisx0208, c1, c2)); | |
| 5044 } | |
| 5034 return val; | 5045 return val; |
| 5035 } | 5046 } |
| 5036 | 5047 |
| 5037 DEFUN ("encode-sjis-char", Fencode_sjis_char, Sencode_sjis_char, 1, 1, 0, | 5048 DEFUN ("encode-sjis-char", Fencode_sjis_char, Sencode_sjis_char, 1, 1, 0, |
| 5038 "Encode a JISX0208 character CHAR to SJIS coding system.\n\ | 5049 "Encode a Japanese character CHAR to shift_jis encoding.\n\ |
| 5039 Return the corresponding character code in SJIS.") | 5050 Return the corresponding code in SJIS.") |
| 5040 (ch) | 5051 (ch) |
| 5041 Lisp_Object ch; | 5052 Lisp_Object ch; |
| 5042 { | 5053 { |
| 5043 int charset, c1, c2, s1, s2; | 5054 int charset, c1, c2, s1, s2; |
| 5044 Lisp_Object val; | 5055 Lisp_Object val; |
| 5045 | 5056 |
| 5046 CHECK_NUMBER (ch, 0); | 5057 CHECK_NUMBER (ch, 0); |
| 5047 SPLIT_CHAR (XFASTINT (ch), charset, c1, c2); | 5058 SPLIT_CHAR (XFASTINT (ch), charset, c1, c2); |
| 5048 if (charset == charset_jisx0208) | 5059 if (charset == charset_jisx0208 |
| 5060 && c1 > 0x20 && c1 < 0x7F && c2 > 0x20 && c2 < 0x7F) | |
| 5049 { | 5061 { |
| 5050 ENCODE_SJIS (c1, c2, s1, s2); | 5062 ENCODE_SJIS (c1, c2, s1, s2); |
| 5051 XSETFASTINT (val, (s1 << 8) | s2); | 5063 XSETFASTINT (val, (s1 << 8) | s2); |
| 5052 } | 5064 } |
| 5065 else if (charset == charset_katakana_jisx0201 | |
| 5066 && c1 > 0x20 && c2 < 0xE0) | |
| 5067 { | |
| 5068 XSETFASTINT (val, c1 | 0x80); | |
| 5069 } | |
| 5053 else | 5070 else |
| 5054 XSETFASTINT (val, 0); | 5071 error ("Can't encode to shift_jis: %d", XFASTINT (ch)); |
| 5072 | |
| 5055 return val; | 5073 return val; |
| 5056 } | 5074 } |
| 5057 | 5075 |
| 5058 DEFUN ("decode-big5-char", Fdecode_big5_char, Sdecode_big5_char, 1, 1, 0, | 5076 DEFUN ("decode-big5-char", Fdecode_big5_char, Sdecode_big5_char, 1, 1, 0, |
| 5059 "Decode a Big5 character CODE of BIG5 coding system.\n\ | 5077 "Decode a Big5 character CODE of BIG5 coding system.\n\ |
