comparison src/coding.c @ 88465:ae455bb40718

(decode_coding_charset, encode_coding_charset): Handle multiple charsets correctly.
author Kenichi Handa <handa@m17n.org>
date Wed, 08 May 2002 04:19:41 +0000
parents a7b309f72920
children b47ee8b1ce03
comparison
equal deleted inserted replaced
88464:2885ae07eac4 88465:ae455bb40718
4256 unsigned char *src_base; 4256 unsigned char *src_base;
4257 int *charbuf = coding->charbuf; 4257 int *charbuf = coding->charbuf;
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;
4273 4272
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))
4288 c = '\n'; 4286 c = '\n';
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 }
4296 *charbuf++ = c; 4317 *charbuf++ = c;
4297 continue; 4318 continue;
4325 Lisp_Object attrs, eol_type, charset_list; 4346 Lisp_Object attrs, eol_type, charset_list;
4326 int ascii_compatible; 4347 int ascii_compatible;
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;
4349 coding->produced_char += produced_chars; 4383 coding->produced_char += produced_chars;
4350 coding->produced = dst - coding->destination; 4384 coding->produced = dst - coding->destination;