aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorKenichi Handa1999-02-16 01:38:01 +0000
committerKenichi Handa1999-02-16 01:38:01 +0000
commitc28a9453f6fa3cd9894fc42c6155d46d848e494f (patch)
treea683fbe8e8cd2c0f14054998e9704835b8975bad /src/coding.c
parent2751e20bad749fe01d7c885f5fdd51193599530c (diff)
downloademacs-c28a9453f6fa3cd9894fc42c6155d46d848e494f.tar.gz
emacs-c28a9453f6fa3cd9894fc42c6155d46d848e494f.zip
(Fdecode_sjis_char, Fencode_sjis_char): Hanlde
ASCII correctly. Signal error on invalid characters. (Fdecode_big5_char, Fencode_big5_char): Likewise.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/src/coding.c b/src/coding.c
index 45cfb053930..15eadaf58ff 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -2034,7 +2034,7 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
2034 (character set) (range) 2034 (character set) (range)
2035 ASCII 0x00 .. 0x7F 2035 ASCII 0x00 .. 0x7F
2036 KATAKANA-JISX0201 0xA0 .. 0xDF 2036 KATAKANA-JISX0201 0xA0 .. 0xDF
2037 JISX0208 (1st byte) 0x80 .. 0x9F and 0xE0 .. 0xEF 2037 JISX0208 (1st byte) 0x81 .. 0x9F and 0xE0 .. 0xEF
2038 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC 2038 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC
2039 ------------------------------- 2039 -------------------------------
2040 2040
@@ -5034,15 +5034,19 @@ Return the corresponding character.")
5034 s1 = (XFASTINT (code)) >> 8, s2 = (XFASTINT (code)) & 0xFF; 5034 s1 = (XFASTINT (code)) >> 8, s2 = (XFASTINT (code)) & 0xFF;
5035 if (s1 == 0) 5035 if (s1 == 0)
5036 { 5036 {
5037 if (s2 < 0xA0 || s2 > 0xDF) 5037 if (s2 < 0x80)
5038 error ("Invalid Shift JIS code: %s", XFASTINT (code)); 5038 XSETFASTINT (val, s2);
5039 XSETFASTINT (val, MAKE_NON_ASCII_CHAR (charset_katakana_jisx0201, s2, 0)); 5039 else if (s2 >= 0xA0 || s2 <= 0xDF)
5040 XSETFASTINT (val,
5041 MAKE_NON_ASCII_CHAR (charset_katakana_jisx0201, s2, 0));
5042 else
5043 error ("Invalid Shift JIS code: %d", XFASTINT (code));
5040 } 5044 }
5041 else 5045 else
5042 { 5046 {
5043 if ((s1 < 0x80 || s1 > 0x9F && s1 < 0xE0 || s1 > 0xEF) 5047 if ((s1 < 0x80 || s1 > 0x9F && s1 < 0xE0 || s1 > 0xEF)
5044 || (s2 < 0x40 || s2 == 0x7F || s2 > 0xFC)) 5048 || (s2 < 0x40 || s2 == 0x7F || s2 > 0xFC))
5045 error ("Invalid Shift JIS code: %s", XFASTINT (code)); 5049 error ("Invalid Shift JIS code: %d", XFASTINT (code));
5046 DECODE_SJIS (s1, s2, c1, c2); 5050 DECODE_SJIS (s1, s2, c1, c2);
5047 XSETFASTINT (val, MAKE_NON_ASCII_CHAR (charset_jisx0208, c1, c2)); 5051 XSETFASTINT (val, MAKE_NON_ASCII_CHAR (charset_jisx0208, c1, c2));
5048 } 5052 }
@@ -5060,8 +5064,12 @@ Return the corresponding code in SJIS.")
5060 5064
5061 CHECK_NUMBER (ch, 0); 5065 CHECK_NUMBER (ch, 0);
5062 SPLIT_CHAR (XFASTINT (ch), charset, c1, c2); 5066 SPLIT_CHAR (XFASTINT (ch), charset, c1, c2);
5063 if (charset == charset_jisx0208 5067 if (charset == CHARSET_ASCII)
5064 && c1 > 0x20 && c1 < 0x7F && c2 > 0x20 && c2 < 0x7F) 5068 {
5069 val = ch;
5070 }
5071 else if (charset == charset_jisx0208
5072 && c1 > 0x20 && c1 < 0x7F && c2 > 0x20 && c2 < 0x7F)
5065 { 5073 {
5066 ENCODE_SJIS (c1, c2, s1, s2); 5074 ENCODE_SJIS (c1, c2, s1, s2);
5067 XSETFASTINT (val, (s1 << 8) | s2); 5075 XSETFASTINT (val, (s1 << 8) | s2);
@@ -5073,13 +5081,11 @@ Return the corresponding code in SJIS.")
5073 } 5081 }
5074 else 5082 else
5075 error ("Can't encode to shift_jis: %d", XFASTINT (ch)); 5083 error ("Can't encode to shift_jis: %d", XFASTINT (ch));
5076
5077 return val; 5084 return val;
5078} 5085}
5079 5086
5080DEFUN ("decode-big5-char", Fdecode_big5_char, Sdecode_big5_char, 1, 1, 0, 5087DEFUN ("decode-big5-char", Fdecode_big5_char, Sdecode_big5_char, 1, 1, 0,
5081 "Decode a Big5 character CODE of BIG5 coding system.\n\ 5088 "Decode a Big5 character which has CODE in BIG5 coding system.\n\
5082CODE is the character code in BIG5.\n\
5083Return the corresponding character.") 5089Return the corresponding character.")
5084 (code) 5090 (code)
5085 Lisp_Object code; 5091 Lisp_Object code;
@@ -5090,8 +5096,20 @@ Return the corresponding character.")
5090 5096
5091 CHECK_NUMBER (code, 0); 5097 CHECK_NUMBER (code, 0);
5092 b1 = (XFASTINT (code)) >> 8, b2 = (XFASTINT (code)) & 0xFF; 5098 b1 = (XFASTINT (code)) >> 8, b2 = (XFASTINT (code)) & 0xFF;
5093 DECODE_BIG5 (b1, b2, charset, c1, c2); 5099 if (b1 == 0)
5094 XSETFASTINT (val, MAKE_NON_ASCII_CHAR (charset, c1, c2)); 5100 {
5101 if (b2 >= 0x80)
5102 error ("Invalid BIG5 code: %d", XFASTINT (code));
5103 val = code;
5104 }
5105 else
5106 {
5107 if ((b1 < 0xA1 || b1 > 0xFE)
5108 || (b2 < 0x40 || (b2 > 0x7E && b2 < 0xA1) || b2 > 0xFE))
5109 error ("Invalid BIG5 code: %d", XFASTINT (code));
5110 DECODE_BIG5 (b1, b2, charset, c1, c2);
5111 XSETFASTINT (val, MAKE_NON_ASCII_CHAR (charset, c1, c2));
5112 }
5095 return val; 5113 return val;
5096} 5114}
5097 5115
@@ -5106,13 +5124,20 @@ Return the corresponding character code in Big5.")
5106 5124
5107 CHECK_NUMBER (ch, 0); 5125 CHECK_NUMBER (ch, 0);
5108 SPLIT_CHAR (XFASTINT (ch), charset, c1, c2); 5126 SPLIT_CHAR (XFASTINT (ch), charset, c1, c2);
5109 if (charset == charset_big5_1 || charset == charset_big5_2) 5127 if (charset == CHARSET_ASCII)
5128 {
5129 val = ch;
5130 }
5131 else if ((charset == charset_big5_1
5132 && (XFASTINT (ch) >= 0x250a1 && XFASTINT (ch) <= 0x271ec))
5133 || (charset == charset_big5_2
5134 && XFASTINT (ch) >= 0x290a1 && XFASTINT (ch) <= 0x2bdb2))
5110 { 5135 {
5111 ENCODE_BIG5 (charset, c1, c2, b1, b2); 5136 ENCODE_BIG5 (charset, c1, c2, b1, b2);
5112 XSETFASTINT (val, (b1 << 8) | b2); 5137 XSETFASTINT (val, (b1 << 8) | b2);
5113 } 5138 }
5114 else 5139 else
5115 XSETFASTINT (val, 0); 5140 error ("Can't encode to Big5: %d", XFASTINT (ch));
5116 return val; 5141 return val;
5117} 5142}
5118 5143