diff options
| author | Kenichi Handa | 2002-05-08 04:19:41 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2002-05-08 04:19:41 +0000 |
| commit | 4eb6d3f1201a174f9c366a0826fdf740f3ca4f9f (patch) | |
| tree | 82a5161ea3436962e07cb6ce96bc2f35eb1fc5b2 /src/coding.c | |
| parent | 8efbba212be7b5efc3abfa3d59f8294959a4b09f (diff) | |
| download | emacs-4eb6d3f1201a174f9c366a0826fdf740f3ca4f9f.tar.gz emacs-4eb6d3f1201a174f9c366a0826fdf740f3ca4f9f.zip | |
(decode_coding_charset, encode_coding_charset): Handle
multiple charsets correctly.
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 62 |
1 files changed, 48 insertions, 14 deletions
diff --git a/src/coding.c b/src/coding.c index 8067df78d6c..ae7c52918e1 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -4258,15 +4258,14 @@ decode_coding_charset (coding) | |||
| 4258 | int *charbuf_end = charbuf + coding->charbuf_size; | 4258 | int *charbuf_end = charbuf + coding->charbuf_size; |
| 4259 | int consumed_chars = 0, consumed_chars_base; | 4259 | int consumed_chars = 0, consumed_chars_base; |
| 4260 | int multibytep = coding->src_multibyte; | 4260 | int multibytep = coding->src_multibyte; |
| 4261 | struct charset *charset; | 4261 | Lisp_Object attrs, eol_type, charset_list, valids; |
| 4262 | Lisp_Object attrs, eol_type, charset_list; | ||
| 4263 | 4262 | ||
| 4264 | CODING_GET_INFO (coding, attrs, eol_type, charset_list); | 4263 | CODING_GET_INFO (coding, attrs, eol_type, charset_list); |
| 4265 | charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | 4264 | valids = AREF (attrs, coding_attr_charset_valids); |
| 4266 | 4265 | ||
| 4267 | while (1) | 4266 | while (1) |
| 4268 | { | 4267 | { |
| 4269 | int c, c1; | 4268 | int c; |
| 4270 | 4269 | ||
| 4271 | src_base = src; | 4270 | src_base = src; |
| 4272 | consumed_chars_base = consumed_chars; | 4271 | consumed_chars_base = consumed_chars; |
| @@ -4274,14 +4273,13 @@ decode_coding_charset (coding) | |||
| 4274 | if (charbuf >= charbuf_end) | 4273 | if (charbuf >= charbuf_end) |
| 4275 | break; | 4274 | break; |
| 4276 | 4275 | ||
| 4277 | ONE_MORE_BYTE (c1); | 4276 | ONE_MORE_BYTE (c); |
| 4278 | if (c == '\r') | 4277 | if (c == '\r') |
| 4279 | { | 4278 | { |
| 4280 | if (EQ (eol_type, Qdos)) | 4279 | if (EQ (eol_type, Qdos)) |
| 4281 | { | 4280 | { |
| 4282 | if (src == src_end) | 4281 | if (src < src_end |
| 4283 | goto no_more_source; | 4282 | && *src == '\n') |
| 4284 | if (*src == '\n') | ||
| 4285 | ONE_MORE_BYTE (c); | 4283 | ONE_MORE_BYTE (c); |
| 4286 | } | 4284 | } |
| 4287 | else if (EQ (eol_type, Qmac)) | 4285 | else if (EQ (eol_type, Qmac)) |
| @@ -4289,7 +4287,30 @@ decode_coding_charset (coding) | |||
| 4289 | } | 4287 | } |
| 4290 | else | 4288 | else |
| 4291 | { | 4289 | { |
| 4292 | CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c1, c); | 4290 | Lisp_Object val; |
| 4291 | struct charset *charset; | ||
| 4292 | int c1; | ||
| 4293 | |||
| 4294 | val = AREF (valids, c); | ||
| 4295 | if (NILP (val)) | ||
| 4296 | goto invalid_code; | ||
| 4297 | charset = CHARSET_FROM_ID (XFASTINT (val)); | ||
| 4298 | if (CHARSET_DIMENSION (charset) > 1) | ||
| 4299 | { | ||
| 4300 | ONE_MORE_BYTE (c1); | ||
| 4301 | c = (c << 8) | c1; | ||
| 4302 | if (CHARSET_DIMENSION (charset) > 2) | ||
| 4303 | { | ||
| 4304 | ONE_MORE_BYTE (c1); | ||
| 4305 | c = (c << 8) | c1; | ||
| 4306 | if (CHARSET_DIMENSION (charset) > 3) | ||
| 4307 | { | ||
| 4308 | ONE_MORE_BYTE (c1); | ||
| 4309 | c = (c << 8) | c1; | ||
| 4310 | } | ||
| 4311 | } | ||
| 4312 | } | ||
| 4313 | CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c, c); | ||
| 4293 | if (c < 0) | 4314 | if (c < 0) |
| 4294 | goto invalid_code; | 4315 | goto invalid_code; |
| 4295 | } | 4316 | } |
| @@ -4327,22 +4348,35 @@ encode_coding_charset (coding) | |||
| 4327 | int c; | 4348 | int c; |
| 4328 | 4349 | ||
| 4329 | CODING_GET_INFO (coding, attrs, eol_type, charset_list); | 4350 | CODING_GET_INFO (coding, attrs, eol_type, charset_list); |
| 4330 | charset = CHARSET_FROM_ID (XINT (XCAR (charset_list))); | ||
| 4331 | ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); | 4351 | ascii_compatible = ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)); |
| 4332 | 4352 | ||
| 4333 | while (charbuf < charbuf_end) | 4353 | while (charbuf < charbuf_end) |
| 4334 | { | 4354 | { |
| 4355 | struct charset *charset; | ||
| 4335 | unsigned code; | 4356 | unsigned code; |
| 4336 | 4357 | ||
| 4337 | ASSURE_DESTINATION (safe_room); | 4358 | ASSURE_DESTINATION (safe_room); |
| 4338 | c = *charbuf++; | 4359 | c = *charbuf++; |
| 4339 | if (ascii_compatible && ASCII_CHAR_P (c)) | 4360 | if (ascii_compatible && ASCII_CHAR_P (c)) |
| 4340 | EMIT_ONE_ASCII_BYTE (c); | 4361 | EMIT_ONE_ASCII_BYTE (c); |
| 4341 | else if ((code = ENCODE_CHAR (charset, c)) | ||
| 4342 | != CHARSET_INVALID_CODE (charset)) | ||
| 4343 | EMIT_ONE_BYTE (code); | ||
| 4344 | else | 4362 | else |
| 4345 | EMIT_ONE_BYTE (coding->default_char); | 4363 | { |
| 4364 | charset = char_charset (c, charset_list, &code); | ||
| 4365 | if (charset) | ||
| 4366 | { | ||
| 4367 | if (CHARSET_DIMENSION (charset) == 1) | ||
| 4368 | EMIT_ONE_BYTE (code); | ||
| 4369 | else if (CHARSET_DIMENSION (charset) == 2) | ||
| 4370 | EMIT_TWO_BYTES (code >> 8, code & 0xFF); | ||
| 4371 | else if (CHARSET_DIMENSION (charset) == 3) | ||
| 4372 | EMIT_THREE_BYTES (code >> 16, (code >> 8) & 0xFF, code & 0xFF); | ||
| 4373 | else | ||
| 4374 | EMIT_FOUR_BYTES (code >> 24, (code >> 16) & 0xFF, | ||
| 4375 | (code >> 8) & 0xFF, code & 0xFF); | ||
| 4376 | } | ||
| 4377 | else | ||
| 4378 | EMIT_ONE_BYTE (coding->default_char); | ||
| 4379 | } | ||
| 4346 | } | 4380 | } |
| 4347 | 4381 | ||
| 4348 | coding->result = CODING_RESULT_SUCCESS; | 4382 | coding->result = CODING_RESULT_SUCCESS; |