Mercurial > emacs
comparison src/coding.c @ 107173:43af18bee02b
Fix the ccl decoder for the case that the output buffer is fullfilled.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 17 Feb 2010 15:52:12 +0900 |
parents | dfc03b454687 |
children | e98bd64897e0 |
comparison
equal
deleted
inserted
replaced
107170:1f564d6c5e1d | 107173:43af18bee02b |
---|---|
5218 const unsigned char *src_end = coding->source + coding->src_bytes; | 5218 const unsigned char *src_end = coding->source + coding->src_bytes; |
5219 int *charbuf = coding->charbuf + coding->charbuf_used; | 5219 int *charbuf = coding->charbuf + coding->charbuf_used; |
5220 int *charbuf_end = coding->charbuf + coding->charbuf_size; | 5220 int *charbuf_end = coding->charbuf + coding->charbuf_size; |
5221 int consumed_chars = 0; | 5221 int consumed_chars = 0; |
5222 int multibytep = coding->src_multibyte; | 5222 int multibytep = coding->src_multibyte; |
5223 struct ccl_program ccl; | 5223 struct ccl_program *ccl = &coding->spec.ccl->ccl; |
5224 int source_charbuf[1024]; | 5224 int source_charbuf[1024]; |
5225 int source_byteidx[1024]; | 5225 int source_byteidx[1024]; |
5226 Lisp_Object attrs, charset_list; | 5226 Lisp_Object attrs, charset_list; |
5227 | 5227 |
5228 CODING_GET_INFO (coding, attrs, charset_list); | 5228 CODING_GET_INFO (coding, attrs, charset_list); |
5229 setup_ccl_program (&ccl, CODING_CCL_DECODER (coding)); | 5229 |
5230 | 5230 while (1) |
5231 while (src < src_end) | |
5232 { | 5231 { |
5233 const unsigned char *p = src; | 5232 const unsigned char *p = src; |
5234 int *source, *source_end; | |
5235 int i = 0; | 5233 int i = 0; |
5236 | 5234 |
5237 if (multibytep) | 5235 if (multibytep) |
5238 while (i < 1024 && p < src_end) | 5236 while (i < 1024 && p < src_end) |
5239 { | 5237 { |
5243 else | 5241 else |
5244 while (i < 1024 && p < src_end) | 5242 while (i < 1024 && p < src_end) |
5245 source_charbuf[i++] = *p++; | 5243 source_charbuf[i++] = *p++; |
5246 | 5244 |
5247 if (p == src_end && coding->mode & CODING_MODE_LAST_BLOCK) | 5245 if (p == src_end && coding->mode & CODING_MODE_LAST_BLOCK) |
5248 ccl.last_block = 1; | 5246 ccl->last_block = 1; |
5249 | 5247 ccl_driver (ccl, source_charbuf, charbuf, i, charbuf_end - charbuf, |
5250 source = source_charbuf; | 5248 charset_list); |
5251 source_end = source + i; | 5249 charbuf += ccl->produced; |
5252 while (source < source_end) | 5250 if (multibytep && ccl->consumed < i) |
5253 { | 5251 src += source_byteidx[ccl->consumed]; |
5254 ccl_driver (&ccl, source, charbuf, | |
5255 source_end - source, charbuf_end - charbuf, | |
5256 charset_list); | |
5257 source += ccl.consumed; | |
5258 charbuf += ccl.produced; | |
5259 if (ccl.status != CCL_STAT_SUSPEND_BY_DST) | |
5260 break; | |
5261 } | |
5262 if (source < source_end) | |
5263 src += source_byteidx[source - source_charbuf]; | |
5264 else | 5252 else |
5265 src = p; | 5253 src += ccl->consumed; |
5266 consumed_chars += source - source_charbuf; | 5254 consumed_chars += ccl->consumed; |
5267 | 5255 if (p == src_end || ccl->status != CCL_STAT_SUSPEND_BY_SRC) |
5268 if (ccl.status != CCL_STAT_SUSPEND_BY_SRC | |
5269 && ccl.status != CODING_RESULT_INSUFFICIENT_SRC) | |
5270 break; | 5256 break; |
5271 } | 5257 } |
5272 | 5258 |
5273 switch (ccl.status) | 5259 switch (ccl->status) |
5274 { | 5260 { |
5275 case CCL_STAT_SUSPEND_BY_SRC: | 5261 case CCL_STAT_SUSPEND_BY_SRC: |
5276 record_conversion_result (coding, CODING_RESULT_INSUFFICIENT_SRC); | 5262 record_conversion_result (coding, CODING_RESULT_INSUFFICIENT_SRC); |
5277 break; | 5263 break; |
5278 case CCL_STAT_SUSPEND_BY_DST: | 5264 case CCL_STAT_SUSPEND_BY_DST: |
5265 record_conversion_result (coding, CODING_RESULT_INSUFFICIENT_DST); | |
5279 break; | 5266 break; |
5280 case CCL_STAT_QUIT: | 5267 case CCL_STAT_QUIT: |
5281 case CCL_STAT_INVALID_CMD: | 5268 case CCL_STAT_INVALID_CMD: |
5282 record_conversion_result (coding, CODING_RESULT_INTERRUPT); | 5269 record_conversion_result (coding, CODING_RESULT_INTERRUPT); |
5283 break; | 5270 break; |
7115 struct coding_system *coding; | 7102 struct coding_system *coding; |
7116 { | 7103 { |
7117 Lisp_Object attrs; | 7104 Lisp_Object attrs; |
7118 Lisp_Object undo_list; | 7105 Lisp_Object undo_list; |
7119 Lisp_Object translation_table; | 7106 Lisp_Object translation_table; |
7107 struct ccl_spec cclspec; | |
7120 int carryover; | 7108 int carryover; |
7121 int i; | 7109 int i; |
7122 | 7110 |
7123 if (BUFFERP (coding->src_object) | 7111 if (BUFFERP (coding->src_object) |
7124 && coding->src_pos > 0 | 7112 && coding->src_pos > 0 |
7147 | 7135 |
7148 attrs = CODING_ID_ATTRS (coding->id); | 7136 attrs = CODING_ID_ATTRS (coding->id); |
7149 translation_table = get_translation_table (attrs, 0, NULL); | 7137 translation_table = get_translation_table (attrs, 0, NULL); |
7150 | 7138 |
7151 carryover = 0; | 7139 carryover = 0; |
7140 if (coding->decoder == decode_coding_ccl) | |
7141 { | |
7142 coding->spec.ccl = &cclspec; | |
7143 setup_ccl_program (&cclspec.ccl, CODING_CCL_DECODER (coding)); | |
7144 } | |
7152 do | 7145 do |
7153 { | 7146 { |
7154 EMACS_INT pos = coding->dst_pos + coding->produced_char; | 7147 EMACS_INT pos = coding->dst_pos + coding->produced_char; |
7155 | 7148 |
7156 coding_set_source (coding); | 7149 coding_set_source (coding); |
7163 produce_annotation (coding, pos); | 7156 produce_annotation (coding, pos); |
7164 for (i = 0; i < carryover; i++) | 7157 for (i = 0; i < carryover; i++) |
7165 coding->charbuf[i] | 7158 coding->charbuf[i] |
7166 = coding->charbuf[coding->charbuf_used - carryover + i]; | 7159 = coding->charbuf[coding->charbuf_used - carryover + i]; |
7167 } | 7160 } |
7168 while (coding->consumed < coding->src_bytes | 7161 while (coding->result == CODING_RESULT_INSUFFICIENT_DST |
7169 && (coding->result == CODING_RESULT_SUCCESS | 7162 || (coding->consumed < coding->src_bytes |
7170 || coding->result == CODING_RESULT_INVALID_SRC)); | 7163 && (coding->result == CODING_RESULT_SUCCESS |
7164 || coding->result == CODING_RESULT_INVALID_SRC))); | |
7171 | 7165 |
7172 if (carryover > 0) | 7166 if (carryover > 0) |
7173 { | 7167 { |
7174 coding_set_destination (coding); | 7168 coding_set_destination (coding); |
7175 coding->charbuf_used = carryover; | 7169 coding->charbuf_used = carryover; |