comparison src/coding.c @ 24324:2eec590faf26

(Fdecode_sjis_char, Fencode_sjis_char): Hanlde ASCII correctly. Signal error on invalid characters. (Fdecode_big5_char, Fencode_big5_char): Likewise.
author Kenichi Handa <handa@m17n.org>
date Tue, 16 Feb 1999 01:38:01 +0000
parents 4efecaf73aac
children 8b7ef7fb9e2e
comparison
equal deleted inserted replaced
24323:c1bb999de64e 24324:2eec590faf26
2032 2032
2033 --- CODE RANGE of SJIS --- 2033 --- CODE RANGE of SJIS ---
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
2041 */ 2041 */
2042 2042
5032 5032
5033 CHECK_NUMBER (code, 0); 5033 CHECK_NUMBER (code, 0);
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 }
5049 return val; 5053 return val;
5050 } 5054 }
5058 int charset, c1, c2, s1, s2; 5062 int charset, c1, c2, s1, s2;
5059 Lisp_Object val; 5063 Lisp_Object val;
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);
5068 } 5076 }
5069 else if (charset == charset_katakana_jisx0201 5077 else if (charset == charset_katakana_jisx0201
5071 { 5079 {
5072 XSETFASTINT (val, c1 | 0x80); 5080 XSETFASTINT (val, c1 | 0x80);
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
5080 DEFUN ("decode-big5-char", Fdecode_big5_char, Sdecode_big5_char, 1, 1, 0, 5087 DEFUN ("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\
5082 CODE is the character code in BIG5.\n\
5083 Return the corresponding character.") 5089 Return the corresponding character.")
5084 (code) 5090 (code)
5085 Lisp_Object code; 5091 Lisp_Object code;
5086 { 5092 {
5087 int charset; 5093 int charset;
5088 unsigned char b1, b2, c1, c2; 5094 unsigned char b1, b2, c1, c2;
5089 Lisp_Object val; 5095 Lisp_Object val;
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
5098 DEFUN ("encode-big5-char", Fencode_big5_char, Sencode_big5_char, 1, 1, 0, 5116 DEFUN ("encode-big5-char", Fencode_big5_char, Sencode_big5_char, 1, 1, 0,
5099 "Encode the Big5 character CHAR to BIG5 coding system.\n\ 5117 "Encode the Big5 character CHAR to BIG5 coding system.\n\
5104 int charset, c1, c2, b1, b2; 5122 int charset, c1, c2, b1, b2;
5105 Lisp_Object val; 5123 Lisp_Object val;
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
5119 DEFUN ("set-terminal-coding-system-internal", 5144 DEFUN ("set-terminal-coding-system-internal",
5120 Fset_terminal_coding_system_internal, 5145 Fset_terminal_coding_system_internal,